<?php

namespace App\Http\Controllers\Api\V1\ItemMaster;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\ItemMaster\UnitOptionStoreRequest;
use App\Services\ItemMaster\UnitOptionService;

class UnitOptionController extends Controller
{
    public function __construct(
        protected UnitOptionService $service,
    ) {}

    /**
     * 단위 옵션 목록
     */
    public function index()
    {
        return ApiResponse::handle(function () {
            return $this->service->index();
        }, __('message.fetched'));
    }

    /**
     * 단위 옵션 생성
     */
    public function store(UnitOptionStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.created'));
    }

    /**
     * 단위 옵션 삭제
     */
    public function destroy(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->destroy($id);

            return 'success';
        }, __('message.deleted'));
    }
}
