<?php

namespace App\Domains\Budget\Controllers;

use App\Enumerations\InvoiceType;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListController extends CommonController
{
    public function __invoke(int $costUnitId, string $estimateType, Request $request) : JsonResponse {
        $costUnit = $this->costUnits->getById($costUnitId);
        $estimates = $this->estimates->getEstimates($costUnit, $estimateType);

        return response()->json([
            'status' => 'success',
            'costUnitId' => $costUnitId,
            'title' => InvoiceType::where('slug', $estimateType)->first()->name,
            'estimateType' => $estimateType,
            'estimates' => $estimates,
            'totalAmountString' => $this->estimates->getTotalAmount($costUnit, $estimateType)->toString(),
        ]);
    }

}
