<?php

namespace App\Modules\PaxInformationRoomPassenger\Domain;

use App\Modules\Passenger\Domain\IdPassenger;
use App\Modules\PaxInformation\Domain\PaxInformation;
use App\Modules\PaxInformationRoom\Domain\IdPaxInformationRoom;
use App\Modules\PaxInformationRoom\Domain\PaxInformationRoom;
use App\Modules\Shared\Domain\Aggregate\AggregateAttribute;
use App\Modules\Shared\Domain\Aggregate\AggregateRoot;
use App\Modules\Passenger\Domain\Passenger;

class PaxInformationRoomPassenger extends AggregateRoot
{

    /** @return AgregateAttribute[] */
    public static function attributes(): array
    {
        return [
            new AggregateAttribute('id', IdPaxInformationRoomPassenger::class, 'Id_PaxInformationRoomPassenger', 'primary'),
            new AggregateAttribute('date', PaxInformationRoomPassengerDate::class, 'PaxInformationRoomPassenger_Date'),
            new AggregateAttribute('dateUpdate', PaxInformationRoomPassengerDateUpdate::class, 'PaxInformationRoomPassenger_DateUpdate'),
            new AggregateAttribute('version', PaxInformationRoomPassengerVersion::class, 'PaxInformationRoomPassenger_Version'),
            new AggregateAttribute('status', PaxInformationRoomPassengerStatus::class, 'PaxInformationRoomPassenger_Status'),
            new AggregateAttribute('idPaxInformationRoom', IdPaxInformationRoom::class, 'Id_PaxInformationRoom'),
            new AggregateAttribute('idPassenger', IdPassenger::class, 'Id_Passenger'),
        ];
    }

    public static function table(): string
    {
        return 't_pax_information_room_passenger';
    }

    public function __construct(
        protected IdPaxInformationRoomPassenger $id,
        protected PaxInformationRoomPassengerDate $date,
        protected PaxInformationRoomPassengerDateUpdate $dateUpdate,
        protected PaxInformationRoomPassengerVersion $version,
        protected PaxInformationRoomPassengerStatus $status,
        protected IdPaxInformationRoom $idPaxInformationRoom,
        protected IdPassenger $idPassenger,
        protected ?PaxInformationRoom $paxInformationRoom = null,
        protected ?Passenger $passenger = null
    ) {}

    public static function create(
        IdPaxInformationRoomPassenger $id,
        PaxInformationRoomPassengerDate $date,
        PaxInformationRoomPassengerDateUpdate $dateUpdate,
        PaxInformationRoomPassengerVersion $version,
        PaxInformationRoomPassengerStatus $status,
        IdPaxInformationRoom $idPaxInformationRoom,
        IdPassenger $idPassenger
    ) {
        $model = new self(
            $id,
            $date,
            $dateUpdate,
            $version,
            $status,
            $idPaxInformationRoom,
            $idPassenger,
        );
        return $model;
    }

    public function getVersion(): int
    {
        return $this->version()->value();
    }

    public function id(): IdPaxInformationRoomPassenger
    {
        return $this->id;
    }

    public function date(): PaxInformationRoomPassengerDate
    {
        return $this->date;
    }

    public function dateUpdate(): PaxInformationRoomPassengerDateUpdate
    {
        return $this->dateUpdate;
    }

    public function version(): PaxInformationRoomPassengerVersion
    {
        return $this->version;
    }

    public function status(): PaxInformationRoomPassengerStatus
    {
        return $this->status;
    }

    public function idPassenger(): IdPassenger
    {
        return $this->idPassenger;
    }

    public function idPaxInformationRoom(): IdPaxInformationRoom
    {
        return $this->idPaxInformationRoom;
    }

    public function paxInformationRoom(): PaxInformationRoom
    {
        return $this->paxInformationRoom;
    }

    public function passenger(): Passenger
    {
        return $this->passenger;
    }

    public function delete()
    {
        $this->status = new PaxInformationRoomPassengerStatus(PaxInformationRoomPassengerStatus::DELETED);
        $this->dateUpdate = PaxInformationRoomPassengerDateUpdate::reduceDatetimeToPeru(PaxInformationRoomPassengerDateUpdate::now());
    }

    public function setId(IdPaxInformationRoomPassenger $id): void
    {
        $this->id = $id;
    }

    public function setStatus(PaxInformationRoomPassengerStatus $status): void
    {
        $this->status = $status;
    }

    public function setPaxInformationRoom(PaxInformationRoom $paxInformationRoom): void
    {
        $this->paxInformationRoom = $paxInformationRoom;
    }

    public function setPassenger(Passenger $passenger): void
    {
        $this->passenger = $passenger;
    }

    public function updateDateUpdate(): void
    {
        $this->dateUpdate = PaxInformationRoomPassengerDateUpdate::reduceDatetimeToPeru(PaxInformationRoomPassengerDateUpdate::now());
    }

    public function updateVersion(): void
    {
        $this->version = new PaxInformationRoomPassengerVersion($this->version->value() + 1);
    }
}
