package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.app.MainPageService;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.merchantProfit.MerchantProfitService;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.vo.MerchantProfitVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
public class MainPageController {

    @Autowired
    private UserAppService userAppService;

    @Autowired
    private MainPageService promoterMainPageService;

    @Autowired
    private MainPageService agentStaffMainPageService;
    @Resource
    private MerchantProfitService merchantProfitService;

    /**
     * @page 商户推广
     * 查询推广页统计数据
     * @return
     */
    @PostMapping("/userApp/queryPromotePageData")
    @ApiOperation(tags = {"页面-商户推广"}, value = "查询推广页统计数据", notes = "查询推广页统计数据", httpMethod = "POST")
    public Result<?> getSpreadData() {
        UserApp userApp = userAppService.queryUserAppByToken();
        Map<String, Object> resultMap;
        resultMap = promoterMainPageService.getSpreadData(userApp.getUserId() + "");

        return ResultGenerator.genSuccessResult(resultMap);
    }
    @GetMapping("/userApp/modifyFee")
    public Result<Object> modifyFee(@RequestParam("id") Integer id, @RequestParam("fee") BigDecimal fee){
        UserApp result = userAppService.queryUserBaseInfoByToken();
        promoterMainPageService.modifyFee(result.getUserId(), id, fee);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 团队管理
     * @param name
     * @param current
     * @param size
     * @param typeCode
     * @return
     */
    @GetMapping("/userApp/teamControl")
    public Result<Object> teamControl(String name,
                                      @RequestParam(defaultValue = "1") Integer current,
                                      @RequestParam(defaultValue = "10") Integer size,
                                      @RequestParam("typeCode") String typeCode){
        UserApp result = userAppService.queryUserBaseInfoByToken();
        Map<String, Object> merchantProfitVOS = merchantProfitService.teamList(typeCode, result.getUserId(),
                current,size,name);
        return ResultGenerator.genSuccessResult(merchantProfitVOS);
    }

    /**
     * 创客团队管理
     * @param name
     * @param current
     * @param size
     * @param typeCode
     * @return
     */
    @GetMapping("/userApp/teamQuotaControl")
    public Result<Object> teamQuotaControl(String name,
                                      @RequestParam(defaultValue = "1") Integer current,
                                      @RequestParam(defaultValue = "10") Integer size,
                                      @RequestParam("typeCode") String typeCode){
        UserApp result = userAppService.queryUserBaseInfoByToken();
        Map<String, Object> merchantProfitVOS = merchantProfitService.teamQuotaList(typeCode, result.getUserId(),
                current,size,name);
        return ResultGenerator.genSuccessResult(merchantProfitVOS);
    }

}
