<?php

namespace App\DTO;

use App\Enum\TaskSchemaStatus;
use App\Enum\TaskStatus;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Validator\Constraints as Assert;

class TaskSchemaRequest
{
    public function __construct(
        #[Assert\NotBlank]
        #[Assert\Length(max: 255)]
        public readonly string $name,

        #[Assert\NotNull]
        public readonly TaskSchemaStatus $status = TaskSchemaStatus::Active,

        #[Assert\NotNull]
        public readonly TaskStatus $taskStatus = TaskStatus::Active,

        #[Context([DateTimeNormalizer::FORMAT_KEY => '!Y-m-d'])]
        public readonly ?\DateTimeImmutable $date = null,

        public ?array $repeat = null,

        #[Context([DateTimeNormalizer::FORMAT_KEY => '!Y-m-d'])]
        public readonly ?\DateTimeImmutable $start = null,

        #[Context([DateTimeNormalizer::FORMAT_KEY => '!Y-m-d'])]
        public readonly ?\DateTimeImmutable $end = null,
    ) {
        if (isset($this->repeat['days']) && is_array($this->repeat['days'])) {
            $this->repeat['days'] = array_values(array_unique($this->repeat['days']));
        }
    }
}
