package com.ytpm.controller;

import com.ytpm.advertise.param.AddAppParam;
import com.ytpm.advertise.param.AddPlacementParam;
import com.ytpm.advertise.param.ComprehensiveReportParam;
import com.ytpm.advertise.param.ConcurrentHourReportsParams;
import com.ytpm.advertise.param.HourReportParam;
import com.ytpm.advertise.param.RelativeChannelParam;
import com.ytpm.advertise.param.UnitsParam;
import com.ytpm.advertise.view.AddAppResponse;
import com.ytpm.advertise.view.AddPlacementResponse;
import com.ytpm.advertise.view.AppV1View;
import com.ytpm.advertise.view.ComprehensiveAppReport;
import com.ytpm.advertise.view.ComprehensiveReportView;
import com.ytpm.advertise.view.HourReportRes;
import com.ytpm.advertise.view.HourReportView;
import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.service.TakuApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Collections;
import java.util.List;

@Api("Taku广告聚合管理模块")
@RestController
@RequestMapping("/advertise")
public class AdvertiseController {

    @Autowired
    private TakuApiService takuApiService;

    /**
     * Taku应用关联广告平台
     */
    @ApiOperation("Taku应用关联广告平台")
    @PostMapping("/relativePlatform")
    public Result<?> relativePlatform(@RequestBody RelativeChannelParam channelParam) {
        return takuApiService.relativePlatform(channelParam);
    }

    /**
     * 查询应用列表
     */
    @ApiOperation("查询应用列表")
    @GetMapping("/getAppList")
    public ResultTable<AppV1View> getAppList(@RequestParam(value = "takuPublicKey", required = false) String takuPublicKey) {
        return takuApiService.getAppList(takuPublicKey);
    }

    /**
     * 新增应用
     */
    @ApiOperation("新增应用")
    @PostMapping("/saveApp")
    public Result<AddAppResponse> saveApp(@RequestBody AddAppParam param) {
        return takuApiService.saveApp(param);
    }

    /**
     * 删除应用
     */
    @ApiOperation("删除应用")
    @GetMapping("/delApp")
    public Result<AddAppResponse> delApp(@RequestParam("appId")String appId,@RequestParam("takuPublicKey") String takuPublicKey) {
        return takuApiService.delApp(appId,takuPublicKey);
    }

    /**
     * 保存广告位
     */
    @ApiOperation("保存广告位")
    @PostMapping("/savePlacement")
    public ResultTable<AddPlacementResponse> savePlacement(@RequestBody AddPlacementParam param) {
        return takuApiService.addPlacements(param);
    }

    /**
     * 删除广告位
     */
    @ApiOperation("删除广告位")
    @GetMapping("/delPlacement")
    public Result<?> delPlacement(@RequestParam("placementId")String placementId,@RequestParam("takuPublicKey") String takuPublicKey) {
        return takuApiService.delPlacement(Collections.singletonList(placementId),takuPublicKey);
    }

    /**
     * 删除广告源
     */
    @ApiOperation("删除广告源")
    @GetMapping("/delAdSource")
    public Result<?> delAdSource(@RequestParam("adSourceId")Integer adSourceId,@RequestParam("takuPublicKey") String takuPublicKey) {
        return takuApiService.delUnits(Collections.singletonList(adSourceId),takuPublicKey);
    }

    /**
     * 新增广告源
     */
    @ApiOperation("新增广告源")
    @PostMapping("/saveAdSource")
    public Result<?> saveAdSource(@RequestBody UnitsParam param) {
        return takuApiService.saveUnits(param);
    }

    /**
     * 修改广告源
     */
    @ApiOperation("修改广告源")
    @PostMapping("/updateAdSource")
    public Result<?> updateAdSource(@RequestBody UnitsParam param) {
        return takuApiService.updateUnits(param);
    }

    /**
     * 根据应用分组查询数据报表
     */
    @ApiOperation("根据应用分组查询数据报表")
    @PostMapping("/getAppReport")
    public List<ComprehensiveAppReport> getAppReport(@RequestBody ComprehensiveReportParam param){
        return takuApiService.getAppReport(param);
    }

    /**
     * 根据应用分组查询数据报表
     */
    @ApiOperation("根据应用分组查询数据报表")
    @PostMapping("/comprehensive")
    public Result<ComprehensiveReportView> comprehensive(@RequestBody ComprehensiveReportParam param){
        return takuApiService.comprehensiveReport(param);
    }

    /**
     *查询分小时报表
     */
    @ApiOperation("查询分小时报表")
    @PostMapping("/hourReport")
    public ResultTable<HourReportView>  hourReport(@RequestBody HourReportParam param){
        return takuApiService.hourReport(param);
    }

    /**
     *异步查询分小时报表
     */
    @ApiOperation("异步查询分小时报表")
    @PostMapping("/concurrentHourReports")
    public Result<List<HourReportRes>> concurrentHourReports(@RequestBody ConcurrentHourReportsParams param){
        return takuApiService.concurrentHourReports(param.getParam());
    }
}
