package com.ytpm.lemonios.controller;

import com.ytpm.agent.view.AgentAdGroupStaticsVO;
import com.ytpm.agent.view.AgentTopCountView;
import com.ytpm.annotation.ApiEncrypt;
import com.ytpm.annotation.Internal;
import com.ytpm.app.param.DyzAdRecordDelayParam;
import com.ytpm.app.param.DyzAdRecordParam;
import com.ytpm.general.Result;
import com.ytpm.lemonios.service.AdService;
import com.ytpm.middle.view.DashboardRankingListVO;
import com.ytpm.middle.view.DashboardRevenueVO;
import com.ytpm.middle.view.DashboardRiskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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


@Api(tags = "用户浏览广告记录")
@RestController
@RequestMapping("/ad")
public class AdController {

    @Resource
    private AdService adService;

    /**
     * 保存广告记录
     */
    @ApiOperation("保存")
    @ApiEncrypt(response = true)
    @PostMapping("/saveRecord")
    public Result<?> saveRecord(@RequestBody DyzAdRecordParam param) {
        return adService.saveRecord(param);
    }

    /**
     * 保存广告记录
     */
    @ApiOperation("延迟保存广告记录")
    @ApiEncrypt(response = true)
    @PostMapping("/saveRecord/delay")
    public Result<String> delaySaveRecord(@RequestBody DyzAdRecordDelayParam param) {
        return adService.delaySaveRecord(param);
    }
    /**
     * 根据应用ID查询广告数
     */

    @ApiOperation("根据应用ID查询广告数")
    @GetMapping("/getAdCount")
    public Map<String, BigDecimal> getAdCount(@RequestParam(name = "appIds") String appIds) {
        return adService.getAdCount(appIds);
    }

    /**
     * 查询应用排行榜信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sortBy", value = "排行榜排序规则", required = true),
            @ApiImplicitParam(name = "limit", value = "排行榜显示数量", required = true),
    })

    @ApiOperation("查询应用排行榜信息")
    @GetMapping("/getAppRankingList")
    public DashboardRankingListVO queryRankingList(@RequestParam(name = "sortBy") Integer sortBy, @RequestParam(name = "limit") Integer limit) {
        return adService.queryRankingList(sortBy, limit);
    }

    /**
     * 查询各渠道应用收益分时统计
     */

    @ApiImplicitParam(name = "apkIds", value = "渠道应用ID（,拼接）", required = true)
    @ApiOperation("查询各渠道应用收益分时统计")
    @GetMapping("/revenueStatics")
    public DashboardRevenueVO revenueStatics(@RequestParam(name = "apkIds") String apkIds) {
        return adService.revenueStatics(apkIds);
    }

    @ApiOperation("查询渠道商顶部数据")
    @GetMapping("/getAppTopCount")
    public AgentTopCountView getAppTopCount(@RequestParam(name = "appIds") String appIds) {
        return adService.getAppTopCount(appIds);
    }

    @ApiOperation("查询用户风控分时数据统计")
    @GetMapping("/userStatics")
    public DashboardRiskVO userStatics(@RequestParam(name = "appId") String appId) {
        return adService.userStatics(appId);
    }

    @ApiOperation("查询代理商首页统计广告数据")
    @GetMapping("/getAgentProfit")
    public List<AgentAdGroupStaticsVO> getAgentProfit(@RequestParam(name = "appIds") String appIds) {
        return adService.getAgentProfit(appIds);
    }
}
