<?php

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

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\ItemMaster\SectionTemplateStoreRequest;
use App\Http\Requests\ItemMaster\SectionTemplateUpdateRequest;
use App\Services\ItemMaster\SectionTemplateService;

class SectionTemplateController extends Controller
{
    public function __construct(
        protected SectionTemplateService $service,
    ) {}

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

    /**
     * 섹션 템플릿 생성
     */
    public function store(SectionTemplateStoreRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->service->store($request->validated());
        }, __('message.created'));
    }

    /**
     * 섹션 템플릿 수정
     */
    public function update(int $id, SectionTemplateUpdateRequest $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'));
    }
}
