<?php
/**
 * Candidate product detected from existing affiliate-link data.
 *
 * @package Affilun\Application\Migration
 */

declare(strict_types=1);

namespace Affilun\Application\Migration;

/**
 * Immutable import candidate extracted from existing content.
 */
final class ExternalAffiliateProductCandidate {

	/**
	 * Stable affilun provider key.
	 */
	private string $provider;

	/**
	 * Provider-side product identifier.
	 */
	private string $providerItemId;

	/**
	 * Product title.
	 */
	private string $title;

	/**
	 * Brand or manufacturer name.
	 */
	private ?string $brand;

	/**
	 * Canonical provider detail URL.
	 */
	private string $detailUrl;

	/**
	 * Affiliate-tracked URL.
	 */
	private ?string $affiliateUrl;

	/**
	 * Primary image URL.
	 */
	private ?string $imageUrl;

	/**
	 * Decimal price amount string.
	 */
	private ?string $priceAmount;

	/**
	 * Original block attributes kept for diagnostics/payload preservation.
	 *
	 * @var array<string, mixed>
	 */
	private array $sourceAttributes;

	/**
	 * Construct an import candidate.
	 *
	 * @param string               $provider         Stable provider key.
	 * @param string               $providerItemId   Provider-side identifier.
	 * @param string               $title            Product title.
	 * @param string|null          $brand            Brand or manufacturer.
	 * @param string               $detailUrl        Provider detail URL.
	 * @param string|null          $affiliateUrl     Affiliate-tracked URL.
	 * @param string|null          $imageUrl         Primary image URL.
	 * @param string|null          $priceAmount      Decimal price amount.
	 * @param array<string, mixed> $sourceAttributes Original block attributes.
	 */
	public function __construct(
		string $provider,
		string $providerItemId,
		string $title,
		?string $brand,
		string $detailUrl,
		?string $affiliateUrl,
		?string $imageUrl,
		?string $priceAmount,
		array $sourceAttributes
	) {
		$this->provider         = $provider;
		$this->providerItemId   = $providerItemId;
		$this->title            = $title;
		$this->brand            = $brand;
		$this->detailUrl        = $detailUrl;
		$this->affiliateUrl     = $affiliateUrl;
		$this->imageUrl         = $imageUrl;
		$this->priceAmount      = $priceAmount;
		$this->sourceAttributes = $sourceAttributes;
	}

	/**
	 * Stable provider key.
	 */
	public function provider(): string {
		return $this->provider;
	}

	/**
	 * Provider-side product identifier.
	 */
	public function providerItemId(): string {
		return $this->providerItemId;
	}

	/**
	 * Product title.
	 */
	public function title(): string {
		return $this->title;
	}

	/**
	 * Brand or manufacturer name.
	 */
	public function brand(): ?string {
		return $this->brand;
	}

	/**
	 * Provider detail URL.
	 */
	public function detailUrl(): string {
		return $this->detailUrl;
	}

	/**
	 * Affiliate-tracked URL.
	 */
	public function affiliateUrl(): ?string {
		return $this->affiliateUrl;
	}

	/**
	 * Primary image URL.
	 */
	public function imageUrl(): ?string {
		return $this->imageUrl;
	}

	/**
	 * Decimal price amount.
	 */
	public function priceAmount(): ?string {
		return $this->priceAmount;
	}

	/**
	 * @return array<string, mixed>
	 */
	public function sourceAttributes(): array {
		return $this->sourceAttributes;
	}

	/**
	 * Stable deduplication key.
	 */
	public function identityKey(): string {
		return $this->provider . "\0" . $this->providerItemId;
	}
}
