<?php

namespace App\Classes\Modules\Segments\Processors;

use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
use App\Classes\Modules\Segments\Services\CreatesSegment;
use App\Classes\Modules\Segments\Standards\Rules\CanCreateSegment;
use Illuminate\Database\Eloquent\Model;

class CreateSegmentProcessor
{

    /** @var CanCreateSegment */
    private $canCreateSegment;

    /** @var CreatesSegment */
    private $createsSegment;

    /**
     * CreateSegmentProcessor constructor.
     * @param CanCreateSegment $canCreateSegment
     * @param CreatesSegment $createsSegment
     * @param GeneratesUniqueAccountNumber $generatesUniqueAccountNumber
     */
    public function __construct(CanCreateSegment $canCreateSegment, CreatesSegment $createsSegment)
    {
        $this->canCreateSegment = $canCreateSegment;
        $this->createsSegment = $createsSegment;
    }


    /**
     * @param string $name
     * @param int $companyModuleId
     * @return Model
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function execute(string $name, int $companyModuleId =1): Model {

        $segement_object = new SegmentObject($name, $companyModuleId);

        $this->canCreateSegment->passes($segement_object);

        return $this->createsSegment->execute($segement_object);

    }

}
