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

import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupCreateLog;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreateService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.Map;

@RestController
@RequestMapping("/kuaishou/create")
public class KuaiShouCreateController {

    @Autowired
    private IKuaiShouCreateService kuaiShouCreateService;

    /**
     * 创建 广告组
     *
     * @param groupCreateTemplate
     * @return
     */
    @PostMapping("/createGroups")
    public Result<KuaiShouGroupCreateLog> createGroups(@RequestBody KuaiShouGroupCreateLog groupCreateTemplate) {
        Result<KuaiShouGroupCreateLog> result = new Result<>();
        Map<String, Object> map = kuaiShouCreateService.createGroups(groupCreateTemplate);
        if ((Integer) map.get("code") == 0) {
            result.setSuccess(true);
        } else {
            result.setSuccess(false);
            result.setMessage((String) map.get("message"));
        }
        return result;


    }

    /**
     * 创建创意
     *
     * @param requestJson
     * @return
     */
    @PostMapping("/createCreative")
    public Result<KuaiShouGroupCreateLog> createCreative(@RequestBody JSONObject requestJson) {
        Result<KuaiShouGroupCreateLog> result = new Result<>();
        Map<String, Object> map = kuaiShouCreateService.createCreative(requestJson);
        if ((Integer) map.get("code") == 0) {
            result.setSuccess(true);
        } else {
            result.setSuccess(false);
            result.setMessage((String) map.get("message"));
        }
        return result;


    }


    @PostMapping("/getOptions")
    public JSONArray getOptions(@RequestBody JSONObject requestJson) {
        return kuaiShouCreateService.getOptions(requestJson.getString("loginId"), requestJson.getLong("accountId"));
    }

    @PostMapping("/getChildren")
    public JSONArray getChildren(@RequestBody JSONObject requestJson) {
        return kuaiShouCreateService.getChildren(requestJson.getString("loginId"), requestJson.getLong("campaignId"), requestJson.getLong("accountId"));
    }


}
