<?php

namespace App\Modules\BookingTour\Domain;

use Illuminate\Support\Facades\DB;

class IndexBookingTour
{

    public function __construct(
        private IdBookingTour $id
    ) {}

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

    protected function query()
    {
        BookingTour::select('`bt`');
        $select = BookingTour::select(`bt`);
        $table = BookingTour::table();
        return DB::select(
            "SELECT $select
            FROM `$table` `bt`
            WHERE `bt`.`Id_BookingTour` = ?",
            [
                $this->id->value()
            ]
        );
    }

    protected function analize($data)
    {
        if (!count($data)) {
            throw new BookingTourNotFound();
        }
        return $data[0];
    }
}
