package com.cf.imes.module.system.controller.admin.statistics;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.organ.vo.organ.OrganRespVO;
import com.cf.imes.module.system.controller.admin.statistics.vo.ManageOrgTotalStatisticRespVO;
import com.cf.imes.module.system.controller.admin.statistics.vo.ManageSalesTotalStatisticRespVO;
import com.cf.imes.module.system.controller.admin.statistics.vo.ManageUserActTotalStatisticRespVO;
import com.cf.imes.module.system.controller.admin.statistics.vo.ManageUserTotalStatisticRespVO;
import com.cf.imes.module.system.controller.admin.statistics.vo.OrgStatusGroupStatisticsReqVO;
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
import com.cf.imes.module.system.service.funds.statistics.FundsStatisticsService;
import com.cf.imes.module.system.service.organ.OrganService;
import com.cf.imes.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 管理端分析页管理")
@RestController
@RequestMapping("/system/manage/statistic")
@Validated
@Slf4j
public class ManageStatisticsController {

    @Resource
    private OrganService organService;

    @Resource
    private AdminUserService userService;

    @Resource
    private PurchaseService purchaseService;

    @Resource
    private FundsStatisticsService fundsStatisticsService;

    @GetMapping("/total/org")
    @Operation(summary = "组织总数")
    public CommonResult<ManageOrgTotalStatisticRespVO> getOrgTotal() {
        return success(organService.getOrgTotal());
    }

    @GetMapping("/total/user")
    @Operation(summary = "用户总数")
    public CommonResult<ManageUserTotalStatisticRespVO> getUserTotal() {
        return success(userService.getUserTotal());
    }

    @GetMapping("/total/sales")
    @Operation(summary = "销售额")
    public CommonResult<ManageSalesTotalStatisticRespVO> getSalesTotal() {
        return success(purchaseService.getSalesTotalStatistics());
    }

    @GetMapping("/total/userAct")
    @Operation(summary = "用户活跃数")
    public CommonResult<ManageUserActTotalStatisticRespVO> getUserActTotal() {
        return success(userService.getUserActTotal());
    }

    @GetMapping("/user/status/group")
    @Operation(summary = "新增、注销用户统计")
    public CommonResult<Map<String, Object>> getUserStatusGroupStatistics(@Valid OrgStatusGroupStatisticsReqVO reqVO) {
        return success(userService.getUserStatusGroupStatistics(reqVO));
    }

    @GetMapping("/funds/tradeType/group")
    @Operation(summary = "销售额统计")
    public CommonResult<Map<String, Object>> getFunsTradeTypeGroupStatistics(@Valid OrgStatusGroupStatisticsReqVO reqVO) {
        return success(fundsStatisticsService.getFunsTradeTypeGroupStatistics(reqVO));
    }

    @GetMapping("/org/status/group")
    @Operation(summary = "新增、注销组织数量统计")
    public CommonResult<Map<String, Object>> getOrgStatusGroupStatistics(@Valid OrgStatusGroupStatisticsReqVO reqVO) {
        return success(organService.getOrgStatusGroupStatistics(reqVO));
    }

    @GetMapping("/org/expiring")
    @Operation(summary = "获取即将过期组织分页")
    public CommonResult<PageResult<OrganRespVO>> getAboutExpireOrg(@Valid PageParam param) {
        return success(organService.getOrgAboutExpire(param));
    }

    @GetMapping("/org/expired")
    @Operation(summary = "获取已过期组织分页")
    public CommonResult<PageResult<OrganRespVO>> getExpiredOrg(@Valid PageParam param) {
        return success(organService.getOrgExpired(param));
    }
}
