<?php

namespace App\Modules\Inventory\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Inventory\DTOs\InventoryAttributeWriteData;
use App\Modules\Inventory\Models\InventoryAttribute;
use App\Modules\Inventory\Requests\StoreInventoryAttributeRequest;
use App\Modules\Inventory\Services\InventoryAttributeManagementService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

final class InventoryAttributeCreateController extends Controller
{
    public function __construct(
        private readonly InventoryAttributeManagementService $management,
    ) {}

    public function create(): View
    {
        $this->authorize('create', InventoryAttribute::class);

        return view('pages.inventory.attributes.create', [
            'typeOptions' => $this->management->typeSelectOptions(),
        ]);
    }

    public function store(StoreInventoryAttributeRequest $request): RedirectResponse
    {
        $this->management->store(InventoryAttributeWriteData::fromValidated($request->validated()));

        return redirect()
            ->route('inventory.attributes.index')
            ->with('status', __('inventory.attributes.flash.created'));
    }
}
