<?php

namespace App\Http\Controllers\Api\V1;

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

/**
 * 접대비 현황 컨트롤러
 *
 * CEO 대시보드용 접대비 현황 데이터를 제공합니다.
 */
class EntertainmentController extends Controller
{
    public function __construct(
        private readonly EntertainmentService $entertainmentService
    ) {}

    /**
     * 접대비 현황 요약 조회
     */
    public function summary(Request $request): JsonResponse
    {
        $limitType = $request->query('limit_type', 'quarterly');
        $companyType = $request->query('company_type', 'medium');
        $year = $request->query('year') ? (int) $request->query('year') : null;
        $quarter = $request->query('quarter') ? (int) $request->query('quarter') : null;

        return ApiResponse::handle(function () use ($limitType, $companyType, $year, $quarter) {
            return $this->entertainmentService->getSummary($limitType, $companyType, $year, $quarter);
        }, __('message.fetched'));
    }

    /**
     * 접대비 상세 조회 (모달용)
     */
    public function detail(Request $request): JsonResponse
    {
        $companyType = $request->query('company_type', 'medium');
        $year = $request->query('year') ? (int) $request->query('year') : null;
        $quarter = $request->query('quarter') ? (int) $request->query('quarter') : null;
        $startDate = $request->query('start_date');
        $endDate = $request->query('end_date');

        return ApiResponse::handle(function () use ($companyType, $year, $quarter, $startDate, $endDate) {
            return $this->entertainmentService->getDetail($companyType, $year, $quarter, $startDate, $endDate);
        }, __('message.fetched'));
    }
}
