<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\VatService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
 * 부가세 현황 컨트롤러
 *
 * CEO 대시보드용 부가세 현황 데이터를 제공합니다.
 */
class VatController extends Controller
{
    public function __construct(
        private readonly VatService $vatService
    ) {}

    /**
     * 부가세 현황 요약 조회
     */
    public function summary(Request $request): JsonResponse
    {
        $periodType = $request->query('period_type', 'quarter');
        $year = $request->query('year') ? (int) $request->query('year') : null;
        $period = $request->query('period') ? (int) $request->query('period') : null;

        return ApiResponse::handle(function () use ($periodType, $year, $period) {
            return $this->vatService->getSummary($periodType, $year, $period);
        }, __('message.fetched'));
    }

    /**
     * 부가세 상세 조회 (모달용)
     */
    public function detail(Request $request): JsonResponse
    {
        $periodType = $request->query('period_type', 'quarter');
        $year = $request->query('year') ? (int) $request->query('year') : null;
        $period = $request->query('period') ? (int) $request->query('period') : null;

        return ApiResponse::handle(function () use ($periodType, $year, $period) {
            return $this->vatService->getDetail($periodType, $year, $period);
        }, __('message.fetched'));
    }
}
