<?php

declare(strict_types=1);

namespace App\Domain\SmartLink\Entities;

use App\Domain\SmartLink\ValueObjects\GeoRuleId;
use App\Domain\SmartLink\ValueObjects\SmartLinkId;
use App\Framework\Core\ValueObjects\CountryCode;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\DateTime\Clock;
use App\Framework\DateTime\SystemClock;

/**
 * Geo-Routing Rule definiert länderspezifische Destination-Zuordnungen
 */
final readonly class GeoRoutingRule
{
    public function __construct(
        public GeoRuleId $id,
        public SmartLinkId $linkId,
        public CountryCode $countryCode,
        public string $destinationId,
        public int $priority,
        public Timestamp $createdAt
    ) {
    }

    public static function create(
        SmartLinkId $linkId,
        CountryCode $countryCode,
        string $destinationId,
        int $priority = 0,
        ?Clock $clock = null
    ): self {
        $clock = $clock ?? new SystemClock();

        return new self(
            id: GeoRuleId::generate($clock),
            linkId: $linkId,
            countryCode: $countryCode,
            destinationId: $destinationId,
            priority: $priority,
            createdAt: Timestamp::now()
        );
    }
}
