<?php

namespace App\Classes\Modules\Segments\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Processors\CreateSegmentProcessor;
use App\Http\Resources\SegmentResource;
use App\Models\Segment;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateSegmentLogic extends AbstractControllerLogic
{

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


    /** @var CreateSegmentProcessor  */
    private $createSegmentProcessor;

    /**
     * CreateSegmentLogic constructor.
     * @param CreateSegmentProcessor $createSegmentProcessor
     */
    public function __construct(CreateSegmentProcessor $createSegmentProcessor)
    {
        $this->createSegmentProcessor = $createSegmentProcessor;
    }

    /**
     * @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
    {
        /** @var Segment $segment */
        $segment = $this->createSegmentProcessor->execute($request->input('name'));

        return $this->resourceResponse(new SegmentResource($segment));
    }

}
