package cn.com.ctop.kuaishou.modules.batch.controller;

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yumeng
 * 2019年11月12日10:04:00
 */
@RestController
@RequestMapping("/kuaishou")
public class KuaiShouController {

    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    @Autowired
    private ICtopOauthTokenService tokenService;

    @RequestMapping("report")
    public Map<String, Object> getReport(String accountId, String startDate, String endDate, Integer type, String temporalGranularity) {
        Map<String, Object> result = new HashMap<>();
        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
        if (null != type) {
            if (type == 1) {
                //广告主

            } else if (type == 2) {
                //广告组
                if (null != temporalGranularity && "hourly".equals(temporalGranularity)) {
                    result.put("data", kuaishouInterfaceService.getGroupHourlyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                } else {
                    result.put("data", kuaishouInterfaceService.getGroupDailyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                }
            } else if (type == 3) {
                //广告计划
                if (null != temporalGranularity && "hourly".equals(temporalGranularity)) {
                    result.put("data", kuaishouInterfaceService.getCampaignHourlyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                } else {
                    result.put("data", kuaishouInterfaceService.getCampaignDailyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                }
            } else {
                //广告创意
                if (null != temporalGranularity && "hourly".equals(temporalGranularity)) {
                    result.put("data", kuaishouInterfaceService.getCreativeHourlyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                } else {
                    result.put("data", kuaishouInterfaceService.getCreativeDailyReport(token.getAccessToken(), token.getAccountId(), startDate, endDate, 500, 1));
                }
            }
        }
        return result;
    }
}
