package com.kxs.stat.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;

import com.kxs.common.security.util.SecurityUtils;
import com.kxs.stat.api.dto.statUser.StatUserGetMyTradeDTO;

import com.kxs.stat.api.dto.statUser.StatUserGetTradeDetailDTO;
import com.kxs.stat.api.dto.statUser.StatUserGetUserStatByDayOrMonthDTO;
import com.kxs.stat.api.dto.statUser.StatUserGetUserTradeListDTO;
import com.kxs.stat.api.model.KxsUserActTrade;
import com.kxs.stat.biz.service.KxsMerchantTradeService;
import com.kxs.stat.biz.service.KxsUserActTradeService;
import com.kxs.stat.biz.service.KxsUserTradeService;

import io.swagger.v3.oas.annotations.parameters.RequestBody;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import lombok.RequiredArgsConstructor;

/**
 * 我的创客(StatUser)控制层
 *
 * @author 系统
 * @since 2024-05-15 11:18:44
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("statUser")
public class KxsStatUserController {

    /**
     * 服务对象
     */
    private final KxsUserTradeService kxsUserTradeService;

    private final KxsMerchantTradeService kxsMerchantTradeService;
    private final KxsUserActTradeService kxsUserActTradeService;

    /**
     * 用户详情-获取用户统计数据
     *
     * @param param 访问实体
     * @return 用户详情-获取用户统计数据
     */
    @GetMapping("/getUserStatByDayOrMonth")
    public R getUserStatByDayOrMonth(@ParameterObject @Valid StatUserGetUserStatByDayOrMonthDTO param) {
        return kxsUserTradeService.getUserStatByDayOrMonth(param);
    }



    /**
     * 商户交易记录
     *
     * @param id 商户id
     * @return 商户交易记录
     */
    @GetMapping("/merchantTradeDetail")
    public R merchantTradeDetail(@RequestParam("id") Long id, @RequestParam("month") String month) {
        return kxsMerchantTradeService.merchantTradeDetail(id, month);
    }


    /**
     * 计奖交易-首页交易总额
     *
     * @return 计奖交易-首页交易总额
     */
    @GetMapping("/getHomeAmout")
    public R getHomeAmout() {
        Long userId = SecurityUtils.getUser().getId();
        return kxsUserTradeService.getHomeAmout(userId);
    }


    /**
     *
     * 计奖交易-交易统计页面
     *
     * @param param 查询实体
     * @return 计奖交易-我的业绩
     */
    @GetMapping("/getUserTradeStatList")
    public R getUserTradeStatList(@ParameterObject StatUserGetUserTradeListDTO param) {
        if (param.getUserId().equals(0L)){
            param.setUserId(SecurityUtils.getUser().getId());
        }
        return kxsUserTradeService.getUserTradeStatList(param);
    }


    /**
     * 计奖交易-激活商户统计
     *
     * @param totalType 统计类型 0 个人  1 团队
     * @param
     * @return 计奖交易-激活商户统计
     */
    @GetMapping("/getActivateMerchantList")
    public R getActivateMerchantList(@RequestParam("totalType")Integer totalType, @RequestParam("userId")Long userId,@RequestParam("month")String month) {
        if (userId == 0){
            userId = SecurityUtils.getUser().getId();
        }
        return kxsUserActTradeService.getActivateMerchantList(totalType,userId,month);
    }

    /**
     * 计奖交易-我的业绩
     *
     * @param param 查询实体
     * @return 计奖交易-我的业绩
     */
    @GetMapping("/getMyTrade")
    public R getMyTrade(@ParameterObject StatUserGetMyTradeDTO param) {
        return kxsUserTradeService.getMyTrade(param);
    }

    /**
     * 计奖交易-交易统计页面-交易明细
     *
     * @param param 查询实体
     * @return 计奖交易-交易统计页面-交易明细
     */
    @GetMapping("/getTradeDetail")
    public R getTradeDetail(@ParameterObject StatUserGetTradeDetailDTO param) {
        return kxsUserTradeService.getTradeDetail(param);
    }
}

