<?php

namespace App\Modules\Booking\Domain\FindFrom;

use App\Modules\Shared\Domain\Storage\Criteria\StorageCriteria;
use Illuminate\Support\Facades\DB;

class FindFromBookingTourPassenger implements StorageCriteria
{

    public function __construct(
        private int $id,
    ) {}

    public function run()
    {
        return $this->analize($this->query());
    }

    protected function query()
    {
        return DB::select(
            "SELECT `p`.`Id_Booking`
            FROM `t_booking_tour_passenger` `btp`
            INNER JOIN `t_passenger` `p` ON `p`.`Id_Passenger` = `btp`.`Id_Passenger`
            WHERE `btp`.`Id_BookingTourPassenger` = ?",
            [$this->id]
        );
    }

    protected function analize($data)
    {
        return count($data) ? $data[0] : null;
    }
}
