<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\V1\Plan\PlanIndexRequest;
use App\Http\Requests\V1\Plan\PlanStoreRequest;
use App\Http\Requests\V1\Plan\PlanUpdateRequest;
use App\Services\PlanService;
use Illuminate\Http\JsonResponse;

class PlanController extends Controller
{
    public function __construct(
        private readonly PlanService $planService
    ) {}

    /**
     * 요금제 목록 (관리자용)
     */
    public function index(PlanIndexRequest $request): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->index($request->validated()),
            __('message.fetched')
        );
    }

    /**
     * 활성 요금제 목록 (공개용)
     */
    public function active(): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->active(),
            __('message.fetched')
        );
    }

    /**
     * 요금제 등록
     */
    public function store(PlanStoreRequest $request): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->store($request->validated()),
            __('message.created')
        );
    }

    /**
     * 요금제 상세
     */
    public function show(int $id): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->show($id),
            __('message.fetched')
        );
    }

    /**
     * 요금제 수정
     */
    public function update(PlanUpdateRequest $request, int $id): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->update($id, $request->validated()),
            __('message.updated')
        );
    }

    /**
     * 요금제 삭제
     */
    public function destroy(int $id): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->destroy($id),
            __('message.deleted')
        );
    }

    /**
     * 요금제 활성/비활성 토글
     */
    public function toggle(int $id): JsonResponse
    {
        return ApiResponse::handle(
            fn () => $this->planService->toggle($id),
            __('message.updated')
        );
    }
}
