<?php

namespace App\Domains\CostUnit\Controllers;

use App\Providers\InertiaProvider;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;

class OpenController extends CommonController {
    public function __invoke(int $costUnitId) {
        $costUnit = $this->costUnits->getById($costUnitId);


        $inertiaProvider = new InertiaProvider('CostUnit/Open', [
            'costUnit' => $costUnit
        ]);
        return $inertiaProvider->render();
    }

    public function listInvoices(int $costUnitId, string $invoiceStatus) : JsonResponse {
        $costUnit = $this->costUnits->getById($costUnitId);
        $invoices = $this->invoices->getByStatus($costUnit, $invoiceStatus);

        return response()->json([
            'status' => 'success',
            'costUnit' => $costUnit,
            'invoices' => $invoices,
            'endpoint' => $invoiceStatus,
        ]);
    }
}
