<?php

namespace App\Classes\Modules\Contacts\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Http\Resources\ContactResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateContactLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Created Contact',
            'message' => 'You have successfully created a new Contact'
        ];
    }

    /** @var CreateContactProcessor */
    private $createContactProcessor;

    /**
     * CreateContactLogic constructor.
     * @param CreateContactProcessor $createContactProcessor
     */
    public function __construct(CreateContactProcessor $createContactProcessor)
    {
        $this->createContactProcessor = $createContactProcessor;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        try {

            return $this->resourceResponse(new ContactResource($this->createContactProcessor->execute($request)));

        } catch (\Exception $exception){
            throw new ErrorException($exception->getMessage(), $exception->getCode());
        }

    }

}