<?php

namespace App\Domains\CostUnit\Actions\ChangeCostUnitDetails;

class ChangeCostUnitDetailsCommand {
    private ChangeCostUnitDetailsRequest $request;

    public function __construct(ChangeCostUnitDetailsRequest $request) {
        $this->request = $request;
    }

    public function execute(): ChangeCostUnitDetailsResponse {
        $response = new ChangeCostUnitDetailsResponse();

        $this->request->costUnit->distance_allowance = $this->request->distanceAllowance->getAmount();
        $this->request->costUnit->mail_on_new = $this->request->mailOnNew;
        $this->request->costUnit->billing_deadline = $this->request->billingDeadline;

        $response->success = $this->request->costUnit->save();
        return $response;
    }
}
