package com.zioinfo.kintex.publicsite;

import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.publicsite.dto.PublicGuideDtos.MonthlySummaryDto;
import com.zioinfo.kintex.publicsite.dto.PublicGuideDtos.PublicCalendarEventDto;
import com.zioinfo.kintex.publicsite.dto.PublicGuideDtos.TransportInfoDto;
import com.zioinfo.kintex.publicsite.dto.PublicGuideDtos.VisitorGuideDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 공개 관람객 안내 API (V43 근거 — 비인증 공개, {@code /api/public/**} permitAll).
 * <p>연/월 전시 캘린더 + 방문가이드 + 교통 — 외부 실시간 호출 없이 적재 DB 서빙.
 * <p>기존 {@code PublicSiteController} 의 {@code /api/public/events}(카탈로그)와는 별도 리터럴 경로로 충돌 없음:
 * 이 컨트롤러는 캘린더 뷰(lifecycle·연/월) 기반의 {@code /events/calendar}·{@code /events/monthly-summary} 를 신설한다.
 */
@RestController
@RequestMapping("/api/public")
public class PublicGuideController {

    private final PublicGuideService service;

    public PublicGuideController(PublicGuideService service) {
        this.service = service;
    }

    /**
     * GET /api/public/events/calendar?year=&month=&lifecycle= — 연/월/상태 캘린더(v_event_calendar).
     * <p>필터 없으면 전체(시작일 오름차순, 상한 {@code limit}). lifecycle ∈ UPCOMING|ONGOING|ENDED.
     */
    @GetMapping("/events/calendar")
    public ApiResponse<List<PublicCalendarEventDto>> calendar(
            @RequestParam(required = false) Integer year,
            @RequestParam(required = false) Integer month,
            @RequestParam(required = false) String lifecycle,
            @RequestParam(required = false, defaultValue = "300") int limit) {
        return ApiResponse.ok(service.calendar(year, month, lifecycle, limit));
    }

    /** GET /api/public/events/monthly-summary?year= — 월별 전시 건수 집계(v_event_monthly_summary). */
    @GetMapping("/events/monthly-summary")
    public ApiResponse<List<MonthlySummaryDto>> monthlySummary(@RequestParam(required = false) Integer year) {
        return ApiResponse.ok(service.monthlySummary(year));
    }

    /** GET /api/public/visitor-guide?category= — 방문가이드(교통/주차/입장/편의/접근성/개요). */
    @GetMapping("/visitor-guide")
    public ApiResponse<List<VisitorGuideDto>> visitorGuide(@RequestParam(required = false) String category) {
        return ApiResponse.ok(service.guides(category));
    }

    /** GET /api/public/transport?mode= — 교통수단 구조화(SUBWAY/GTX/BUS/CAR/AIRPORT/KTX). */
    @GetMapping("/transport")
    public ApiResponse<List<TransportInfoDto>> transport(@RequestParam(required = false) String mode) {
        return ApiResponse.ok(service.transport(mode));
    }
}
