<?php
/**
 * Amazon discount sync result.
 *
 * @package Affilun\Application\AmazonDiscount
 */

declare(strict_types=1);

namespace Affilun\Application\AmazonDiscount;

/**
 * Summary returned by one daily category sweep.
 */
final class AmazonDiscountSyncResult {

	/**
	 * @param array<string,int>    $savedByCategory Saved rows by SearchIndex.
	 * @param array<string,string> $errorsByCategory Error messages by SearchIndex.
	 */
	public function __construct(
		private array $savedByCategory,
		private array $errorsByCategory
	) {
	}

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

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

	/**
	 * Return the total saved row count.
	 */
	public function savedCount(): int {
		return array_sum( $this->savedByCategory );
	}

	/**
	 * Return the number of categories replaced successfully.
	 */
	public function succeeded(): int {
		return count( $this->savedByCategory );
	}
}
