package com.zioinfo.cms.dashboard;

import com.zioinfo.cms.analytics.mapper.AnalyticsMapper;
import com.zioinfo.cms.common.ApiResponse;
import com.zioinfo.cms.dashboard.mapper.DashboardMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/** CMS 대시보드 — 콘텐츠/미디어/UGC/회원/성과 요약. */
@RestController
@RequestMapping("/api/cms/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final DashboardMapper mapper;
    private final AnalyticsMapper analyticsMapper;

    @GetMapping("/summary")
    public ApiResponse<Map<String, Object>> summary() {
        Map<String, Object> m = new LinkedHashMap<>();
        m.put("totalContent", mapper.countTotalContent());
        m.put("publishedContent", mapper.countContentByStatus("PUBLISHED"));
        m.put("draftContent", mapper.countContentByStatus("DRAFT"));
        m.put("reviewContent", mapper.countContentByStatus("REVIEW"));
        m.put("mediaCount", mapper.countMedia());
        m.put("pendingUgc", mapper.countPendingUgc());
        m.put("memberCount", mapper.countMembers());
        m.put("totalViews", analyticsMapper.totalViews());
        m.put("totalConversions", analyticsMapper.totalConversions());
        return ApiResponse.ok(m);
    }

    /** 워크플로우 파이프라인(상태별 콘텐츠 수). */
    @GetMapping("/workflow")
    public ApiResponse<List<Map<String, Object>>> workflow() {
        return ApiResponse.ok(mapper.contentByStatus());
    }

    /** 인기 콘텐츠. */
    @GetMapping("/top-content")
    public ApiResponse<?> topContent() {
        return ApiResponse.ok(analyticsMapper.topContent(5));
    }
}
