<?php

namespace App\Modules\Inventory\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Inventory\Models\Warehouse;
use App\Modules\Inventory\Requests\DeactivateWarehouseRequest;
use App\Modules\Inventory\Services\WarehouseLifecycleService;
use Illuminate\Http\RedirectResponse;

class WarehouseDeactivateController extends Controller
{
    public function __construct(
        private readonly WarehouseLifecycleService $lifecycle,
    ) {}

    public function store(DeactivateWarehouseRequest $request, Warehouse $warehouse): RedirectResponse
    {
        $this->authorize('deactivate', $warehouse);
        $this->lifecycle->deactivate($warehouse, $request->user()?->id);

        return redirect()
            ->route('inventory.warehouses.show', $warehouse)
            ->with('status', __('inventory.warehouses.flash.deactivated'));
    }
}
