<?php

namespace App\Modules\Operations\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Operations\Services\WorkflowInboxAssembler;
use Illuminate\Http\Request;
use Illuminate\View\View;

final class WorkflowInboxPageController extends Controller
{
    public function index(Request $request, WorkflowInboxAssembler $assembler): View
    {
        $user = $request->user();
        abort_if($user === null, 403);
        abort_unless(
            $user->can('operations.control.view')
                || $user->can('leave.view')
                || $user->can('attendance.view')
                || $user->can('overtime.view')
                || $user->can('procurement.purchase_orders.view')
                || $user->can('procurement.goods_receipts.view')
                || $user->can('sales.orders.view'),
            403,
        );

        return view('pages.operations.workflow-inbox', [
            'inbox' => $assembler->assemble($user),
        ]);
    }
}
