<?php

namespace App\Domains\CostUnit\Controllers;

use App\Domains\CostUnit\Actions\CreateCostUnit\CreateCostUnitCommand;
use App\Domains\CostUnit\Actions\CreateCostUnit\CreateCostUnitRequest;
use App\Enumerations\CostUnitType;
use App\Models\CostUnit;
use App\Providers\FlashMessageProvider;
use App\Providers\InertiaProvider;
use App\Scopes\CommonController;
use App\ValueObjects\Amount;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateController extends CommonController{
    public function showForm() {
        $inertiaProvider = new InertiaProvider('CostUnit/Create', []);
        return $inertiaProvider->render();
    }

    public function createCostUnitRunningJob(Request $request) : JsonResponse {
        $createCostUnitRequest = new CreateCostUnitRequest(
            $request->get('cost_unit_name'),
            CostUnitType::COST_UNIT_TYPE_RUNNING_JOB,
            Amount::fromString($request->get('distance_allowance')),
            $request->get('mailOnNew')
        );

        $createCostUnitCommand = new CreateCostUnitCommand($createCostUnitRequest);
        $result = $createCostUnitCommand->execute();
        new FlashMessageProvider('Die laufende Tätigkeit wurde erfolgreich angelegt.', 'success');

        return response()->json([]);
    }
}
