<?php

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

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\Violations\Enums\MessageCode;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\Violations\Enums\MessageSeverity;
/**
 * Value object representing a single validation violation.
 *
 * @see https://ucp.dev/2026-01-23/schemas/shopping/types/message_error.json
 */
final class Violation
{
    private string $code;
    private string $content;
    private string $severity;
    private ?string $path;
    private string $content_type;
    private function __construct(string $code, string $content, string $severity, ?string $path = null, string $content_type = 'plain')
    {
        $this->code = $code;
        $this->content = $content;
        $this->severity = $severity;
        $this->path = $path;
        $this->content_type = $content_type;
    }
    public static function missing(string $content, ?string $path = null): self
    {
        return new self(MessageCode::MISSING, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function invalid(string $content, ?string $path = null): self
    {
        return new self(MessageCode::INVALID, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function out_of_stock(string $content, ?string $path = null): self
    {
        return new self(MessageCode::OUT_OF_STOCK, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function payment_declined(string $content, ?string $path = null): self
    {
        return new self(MessageCode::PAYMENT_DECLINED, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function requires_sign_in(string $content, ?string $path = null): self
    {
        return new self(MessageCode::REQUIRES_SIGN_IN, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function requires_3ds(string $content, ?string $path = null): self
    {
        return new self(MessageCode::REQUIRES_3DS, $content, MessageSeverity::REQUIRES_BUYER_INPUT, $path);
    }
    public static function create(string $code, string $content, string $severity, ?string $path = null): self
    {
        return new self($code, $content, $severity, $path);
    }
    public function with_markdown(): self
    {
        return new self($this->code, $this->content, $this->severity, $this->path, 'markdown');
    }
    /**
     * Convert to UCP response format.
     *
     * @return array<string, mixed>
     */
    public function to_array(): array
    {
        $data = ['type' => 'error', 'code' => $this->code, 'content' => $this->content, 'severity' => $this->severity];
        if ('plain' !== $this->content_type) {
            $data['content_type'] = $this->content_type;
        }
        if (null !== $this->path) {
            $data['path'] = $this->path;
        }
        return $data;
    }
}
