<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\TicketBundle\Action\Ticket;

use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Validation\Constraint\UserGroupDoNotExclude;
use Chill\TicketBundle\Entity\Ticket;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\GreaterThan;

final readonly class SetAddresseesCommand
{
    public function __construct(
        /**
         * @var list<UserGroup|User>
         */
        #[UserGroupDoNotExclude]
        #[GreaterThan(0)]
        #[Groups(['read'])]
        public array $addressees,
    ) {}

    public static function fromAddAddresseeCommand(AddAddresseeCommand $command, Ticket $ticket): self
    {
        return new self([
            $command->addressee,
            ...$ticket->getCurrentAddressee(),
        ]);
    }
}
