<?php

declare(strict_types=1);

namespace App\Domain\Consumer;

use DateTimeImmutable;

/**
 * A distribution consumer (firewall/proxy). Bound to a policy that
 * shapes the blocklist they pull. `lastPulledAt` is touched by the
 * blocklist endpoint (M07) — we expose the column now so admin
 * responses can include it.
 */
final class Consumer
{
    public function __construct(
        public readonly int $id,
        public readonly string $name,
        public readonly ?string $description,
        public readonly int $policyId,
        public readonly bool $isActive,
        public readonly bool $auditEnabled,
        public readonly ?int $createdByUserId,
        public readonly DateTimeImmutable $createdAt,
        public readonly ?DateTimeImmutable $lastPulledAt,
    ) {
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'description' => $this->description,
            'policy_id' => $this->policyId,
            'is_active' => $this->isActive,
            'audit_enabled' => $this->auditEnabled,
            'created_by_user_id' => $this->createdByUserId,
            'created_at' => $this->createdAt->format('Y-m-d\TH:i:s\Z'),
            'last_pulled_at' => $this->lastPulledAt?->format('Y-m-d\TH:i:s\Z'),
        ];
    }
}
