<?php

namespace App\Classes\Modules\Segments\ControllersLogic;

use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Resources\ConstantResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Processors\UpdatePostcodeSegmentProcessor;

class UpdateConstantPostcodeLogic  extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Updated Postcode Constant',
            'message' => 'You have successfully updated the Postcode Constant'
        ];
    }

    /** @var UpdatePostcodeSegmentProcessor */
    private $updatePostcodeSegmentProcessor;

    /**
     * UpdateConstantLogic constructor.
     * @param UpdatePostcodeSegmentProcessor $updatePostcodeSegmentProcessor
     */
    public function __construct(
        UpdatePostcodeSegmentProcessor $updatePostcodeSegmentProcessor
    )
    {
        $this->updatePostcodeSegmentProcessor = $updatePostcodeSegmentProcessor;
    }
    /**
     * @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
    {
        $constant = $this->updatePostcodeSegmentProcessor->execute($request->route('id'), $request->input('reference'), $request->input('postcode'));

        return $this->resourceResponse(new ConstantResource($constant));
    }

}
