<?php

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

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\ItemMaster\CustomTabStoreRequest;
use App\Http\Requests\ItemMaster\CustomTabUpdateRequest;
use App\Http\Requests\ItemMaster\ReorderRequest;
use App\Services\ItemMaster\CustomTabService;

class CustomTabController extends Controller
{
    public function __construct(
        protected CustomTabService $service,
    ) {}

    /**
     * 커스텀 탭 목록
     */
    public function index()
    {
        return ApiResponse::handle(function () {
            return $this->service->index();
        }, __('message.fetched'));
    }

    /**
     * 커스텀 탭 생성
     */
    public function store(CustomTabStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.created'));
    }

    /**
     * 커스텀 탭 수정
     */
    public function update(int $id, CustomTabUpdateRequest $request)
    {
        return ApiResponse::handle(function () use ($id, $request) {
            return $this->service->update($id, $request->validated());
        }, __('message.updated'));
    }

    /**
     * 커스텀 탭 삭제
     */
    public function destroy(int $id)
    {
        return ApiResponse::handle(function () use ($id) {
            $this->service->destroy($id);

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

    /**
     * 커스텀 탭 순서 변경
     */
    public function reorder(ReorderRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            $this->service->reorder($request->validated()['items']);

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