<?php

declare(strict_types=1);

namespace App\Infrastructure\Api\RapidMail;

final readonly class Mailing
{
    public function __construct(
        public ?int $id = null,
        public ?string $name = null,
        public ?string $subject = null,
        public ?string $status = null,
        public ?string $type = null,
        public ?int $recipientlistId = null,
        public ?string $createdAt = null,
        public ?string $updatedAt = null,
        public ?string $sentAt = null,
        public ?array $links = null
    ) {
    }

    public static function fromArray(array $data): self
    {
        return new self(
            id: $data['id'] ?? null,
            name: $data['name'] ?? null,
            subject: $data['subject'] ?? null,
            status: $data['status'] ?? null,
            type: $data['type'] ?? null,
            recipientlistId: $data['recipientlist_id'] ?? null,
            createdAt: $data['created'] ?? null,
            updatedAt: $data['updated'] ?? null,
            sentAt: $data['sent'] ?? null,
            links: $data['_links'] ?? null
        );
    }
}
