<?php

namespace App\Modules\Operations\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Operations\Models\OperationalControlEvent;
use App\Modules\Operations\Repositories\OperationalControlEventRepository;
use App\Modules\Operations\Requests\AcknowledgeOperationalControlEventRequest;
use Illuminate\Http\RedirectResponse;

class OperationalControlEventAcknowledgeController extends Controller
{
    public function __construct(
        private readonly OperationalControlEventRepository $events,
    ) {}

    public function store(
        AcknowledgeOperationalControlEventRequest $request,
        OperationalControlEvent $operational_control_event,
    ): RedirectResponse {
        $this->authorize('acknowledge', $operational_control_event);
        $tenantId = (int) $request->user()->tenant_id;
        $this->events->acknowledge($tenantId, (int) $operational_control_event->id, (int) $request->user()->id);

        return redirect()
            ->route('operations.control-center.index')
            ->with('status', __('operations_control.flash.event_acknowledged'));
    }
}
