<?php

declare (strict_types=1);
namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\Violations;

/**
 * Collection of violations.
 */
final class Violations
{
    /**
     * @var array<int, Violation>
     */
    private array $violations;
    /**
     * @param array<int, Violation> $violations
     */
    private function __construct(array $violations)
    {
        $this->violations = $violations;
    }
    /**
     * Create an empty violations collection.
     */
    public static function empty(): self
    {
        return new self([]);
    }
    /**
     * Create a violations collection from one or more violations.
     */
    public static function from(Violation ...$violations): self
    {
        return new self($violations);
    }
    public function add(Violation $violation): self
    {
        return new self([...$this->violations, $violation]);
    }
    public function merge(self $other): self
    {
        return new self(\array_merge($this->violations, $other->violations));
    }
    public function has_violations(): bool
    {
        return !empty($this->violations);
    }
    /**
     * Convert to UCP response format.
     *
     * @return array<int, array<string, mixed>>
     */
    public function to_array(): array
    {
        return \array_map(static fn(Violation $v): array => $v->to_array(), $this->violations);
    }
    /**
     * Get all violations.
     *
     * @return array<int, Violation>
     */
    public function all(): array
    {
        return $this->violations;
    }
}
