<?php

namespace common\logic\Ticket\TicketMessage\Service;

use common\logic\AbstractBuilder;
use common\logic\Ticket\Ticket\Model\Ticket;
use common\logic\Ticket\TicketMessage\Model\TicketMessage;
use common\logic\User\User\Model\User;

class TicketMessageBuilder extends AbstractBuilder
{
    public function instanciateTicketMessage(Ticket $ticket, User $user, string $message = ''): TicketMessage
    {
        $ticketMessage = new TicketMessage();

        $ticketMessage->populateTicket($ticket);
        $ticketMessage->populateUser($user);
        $ticketMessage->message = $message;

        return $ticketMessage;
    }

    public function createTicketMessage(Ticket $ticket, User $user, string $message): TicketMessage
    {
        $ticketMessage = $this->instanciateTicketMessage($ticket, $user, $message);
        $this->saveCreate($ticketMessage);

        return $ticketMessage;
    }
}