<?php

namespace App\Modules\User\Infraestructure;

use App\Modules\Shared\Application\SelectHandler;
use App\Modules\Shared\Domain\DateEnd;
use App\Modules\Shared\Domain\DateStart;
use App\Modules\Shared\Infraestructure\RequestChecker;
use App\Modules\User\Domain\UserRepository;
use App\Modules\User\Domain\IdUser;
use App\Modules\User\Domain\UserEmail;
use App\Modules\User\Domain\UserLastName;
use App\Modules\User\Domain\UserName;
use App\Modules\User\Domain\UserPhone;
use App\Modules\UserCountry\Domain\IdUserCountry;
use Illuminate\Support\Facades\DB;

class MysqlUserRepository implements UserRepository
{

    public function bookingListByTour(
        IdUser $id,
        DateStart $dateStart,
        DateEnd $dateEnd
    ) {
        return RequestChecker::requestSelect(
            'CALL sp_user_booking_list_by_tour(?,?,?,@sts,@cod,@msg)',
            [
                $id->value(),
                $dateStart->value(),
                $dateEnd->value()
            ]
        );
    }

    public function clientUserValidate(
        UserEmail $email,
    ) {
        return (new SelectHandler())->handle(DB::select(
            'CALL sp_client_user_validate(?)',
            [
                $email->value()
            ]
        ));
    }

    public function clientUserInsert(
        UserName $name,
        UserLastName $lastName,
        UserEmail $email,
        UserPhone $phone,
        IdUserCountry $idUserCountry,
    ) {
        return (new SelectHandler())->handle(DB::select(
            'CALL sp_client_user_insert(?,?,?,?,?)',
            [
                $name->getValue(),
                $lastName->getValue(),
                $email->getValue(),
                $phone->getValue(),
                $idUserCountry->value(),
            ]
        ));
    }
}
