<?php

namespace App\Classes\Modules\Announcements\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Announcements\Standards\Rules\CanDeleteAnnouncement;
use App\Classes\Modules\Announcements\Services\FetchesAnnouncement;
use App\Classes\Modules\Announcements\Services\DeletesAnnouncement;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteAnnouncementLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification(): array
    {
        return [
            'title' => 'Delete Announcement',
            'message' => 'You have successfully deleted the Announcement'
        ];
    }

    /** @var CanDeleteAnnouncement */
    private $canDeleteAnnouncement;

    /** @var FetchesAnnouncement */
    private $fetchesAnnouncement;

    /** @var DeletesAnnouncement */
    private $deletesAnnouncement;

    /**
     * DeleteAnnouncementLogic constructor.
     * @param CanDeleteAnnouncement $canDeleteAnnouncement
     * @param FetchesAnnouncement $fetchesAnnouncement
     * @param DeletesAnnouncement $deletesAnnouncement
     */
    public function __construct(
        CanDeleteAnnouncement $canDeleteAnnoucement,
        FetchesAnnouncement $fetchesAnnoucement,
        DeletesAnnouncement $deletesAnnoucement
    ) {
        $this->canDeleteAnnoucement = $canDeleteAnnoucement;
        $this->fetchesAnnoucement = $fetchesAnnoucement;
        $this->deletesAnnoucement = $deletesAnnoucement;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request): JsonResponse
    {

        $this->canDeleteAnnoucement->passes();

        $annoucement = $this->fetchesAnnoucement->execute(['id' => $request->route('id')]);

        $this->deletesAnnoucement->execute($annoucement);

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