<?php

namespace App\DBRealTestSupport\TransactionSupported;

use App\DBRealTestSupport\PassengerMother;
use App\DBRealTestSupport\PaxInformationMother;
use App\DBRealTestSupport\TableCreation;
use App\DBRealTestSupport\TransactionSupported\TSRepositoryMother;
use App\Modules\Passenger\Domain\IdPassenger;
use App\Modules\PaxInformation\Domain\IdPaxInformation;
use App\Modules\PaxInformationRoom\Domain\IdPaxInformationRoom;
use App\Modules\PaxInformationRoomPassenger\Domain\IdPaxInformationRoomPassenger;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassenger;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerDate;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerDateUpdate;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerRepository;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerStatus;
use App\Modules\PaxInformationRoomPassenger\Domain\PaxInformationRoomPassengerVersion;
use Faker\Factory;

class TSPaxInformationRoomPassengerMother
{
    public static function random(
        ?IdPaxInformationRoomPassenger $idPaxInformationRoomPassenger = null,
        ?PaxInformationRoomPassengerVersion $version = null,
        ?IdPaxInformationRoom $idPaxInformationRoom = null,
        ?IdPassenger $idPassenger = null,
    ): PaxInformationRoomPassenger {
        $faker = Factory::create();
        $paxInformation = PaxInformationMother::push1();
        $idBooking = $paxInformation['Id_Booking'];
        $paxInformationRoom = TSPaxInformationRoomMother::random(idPaxInformation: new IdPaxInformation($paxInformation['Id_PaxInformation']));

        $idPaxInformationRoom = $idPaxInformationRoom ?? TSPaxInformationRoomMother::push($paxInformationRoom)->id();
        $idPassenger = $idPassenger ?? new IdPassenger(PassengerMother::push1(idBooking: $idBooking)['Id_Passenger']);
        return new PaxInformationRoomPassenger(
            $idPaxInformationRoomPassenger ?? new IdPaxInformationRoomPassenger(0),
            new PaxInformationRoomPassengerDate(date('Y-m-d H:i:s', time() + rand(100000, 1000000))),
            new PaxInformationRoomPassengerDateUpdate(date('Y-m-d H:i:s', time() + rand(100000, 1000000))),
            $version ?? new PaxInformationRoomPassengerVersion(rand(1, 1000)),
            new PaxInformationRoomPassengerStatus($faker->randomElement(PaxInformationRoomPassengerStatus::validValues())),
            $idPaxInformationRoom,
            $idPassenger
        );
    }

    public static function push(PaxInformationRoomPassenger $model): PaxInformationRoomPassenger
    {
        return TSRepositoryMother::push(PaxInformationRoomPassengerRepository::class, $model);
    }

    public static function clear(): array
    {
        return [
            TableCreation::PAX_INFORMATION_ROOM_PASSENGER,
            ...TSPaxInformationRoomMother::clear(),
        ];
    }
}
