<?php

namespace App\Classes\Modules\Bookings\ControllersLogic;

use App\Classes\Exceptions\AccessForbiddenException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanDeleteBooking;
use App\Classes\Modules\Bookings\Services\DeletesBooking;
use App\Classes\ValueObjects\Constants\KVPKey;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;


class DeleteBookingLockLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Booking Unlock',
            'message' => 'You have successfully unlock the Booking for editing'
        ];
    }

    /** @var CanDeleteBooking */
    private $canDeleteBooking;

    /** @var DeletesBooking */
    private $deletesBooking;

    /** @var FetchesBooking */
    private $fetchesBooking;


    public function __construct(
        CanDeleteBooking $canDeleteBooking,
        DeletesBooking $deletesBooking,
        FetchesBooking $fetchesBooking
    )
    {
        $this->canDeleteBooking = $canDeleteBooking;
        $this->deletesBooking = $deletesBooking;
        $this->fetchesBooking = $fetchesBooking;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws AccessForbiddenException
     */
    public function logic(Request $request) : JsonResponse
    {
        // cief todo: 110 - CanDeleteBookingLock

        $password = $request->input('password');
        if($password !== 'prototype'){
            throw new AccessForbiddenException('Incorrect Password');
        }

        $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
        $booking->attributesKVP()->where('key', KVPKey::BOOKING_IS_LOCKED)->delete();

        return $this->response([]);
    }

}
