package org.jeecg.modules.ads.controller;

import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouReportAnalyzeService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/ai/analyze")
@RestController
public class AiKuaiShouReportAnalyzeCtrl {

    @Autowired
    IAiKuaiShouReportAnalyzeService aiKuaiShouReportAnalyzeService;

    @GetMapping("/getStrategyAndTarget")
    public Result<List<JSONObject>> getStrategyAndTarget(@RequestParam("accountId") Long accountId){
        Result<List<JSONObject>> result=new Result<>();
        result.setResult(aiKuaiShouReportAnalyzeService.getStrategyAndTarget(accountId));
        result.setSuccess(true);
        return result;
    }

    @GetMapping("/getStrategyAndMaterial")
    public Result<List<JSONObject>> getStrategyAndMaterial(@RequestParam("accountId") Long accountId){
        Result<List<JSONObject>> result=new Result<>();
        result.setResult(aiKuaiShouReportAnalyzeService.getStrategyAndMaterial(accountId));
        result.setSuccess(true);
        return result;
    }

    @PostMapping("/report/targetOrMaterial")
    public Result<PageInfo<JSONObject>> targetOrMaterialReport(@RequestBody JSONObject params){
        Result<PageInfo<JSONObject>> result=new Result<>();
        if(params.isEmpty()){
            result.error500("参数为空");
        }else {
            if(params.getString("type").equals("target")){
                result.setResult(aiKuaiShouReportAnalyzeService.getTargetReportBy(params));
            }
            else if(params.getString("type").equals("material")){
                result.setResult(aiKuaiShouReportAnalyzeService.getMaterialReportBy(params));
            }
            result.setSuccess(true);
        }
        return result;
    }

    //TODO 先不加时间维度，现在是t-2
    @PostMapping("/chart/targetOrMaterial")
    public Result<Map<String,Object>> targetOrMaterialChart(@RequestBody JSONObject params){
        Result<Map<String,Object>> result=new Result<>();
        if(params.isEmpty()){
            result.error500("参数为空");
        }else {
            if(params.getString("type").equals("target")){
                result.setResult(aiKuaiShouReportAnalyzeService.getTargetChartBy(params));
            }
            else if(params.getString("type").equals("material")){
                result.setResult(aiKuaiShouReportAnalyzeService.getMaterialChartBy(params));
            }
            result.setSuccess(true);
        }
        return result;
    }

}
