package cn.com.ctop.toutiao.modules.tool.service.impl;

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.utils.HttpUtils;
import cn.com.ctop.toutiao.modules.tool.constants.QueryToolUrlConstant;
import cn.com.ctop.toutiao.modules.tool.service.IByteDanceQueryMaterialInfoService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

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

@Service
public class ByteDanceQueryMaterialInfoServiceImpl implements IByteDanceQueryMaterialInfoService {

    @Override
    public JSONObject queryVideoInfo(CtopOauthToken token, Long accountId, JSONArray signatures) {

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("Access-Token", token.getAccessToken());

        JSONObject params=new JSONObject();
        params.put("advertiser_id",accountId);
        JSONObject filtering=new JSONObject();
        filtering.put("signatures",signatures);
        params.put("filtering",filtering);

        return JSONObject.parseObject(HttpUtils.httpGet(QueryToolUrlConstant.FILE_VIDEO_GET, params, headers));
    }

    @Override
    public JSONObject queryImageInfo(CtopOauthToken token, Long accountId, JSONArray signatures) {

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("Access-Token", token.getAccessToken());

        JSONObject params=new JSONObject();
        params.put("advertiser_id",accountId);
        JSONObject filtering=new JSONObject();
        filtering.put("signatures",signatures);
        params.put("filtering",filtering);

        return JSONObject.parseObject(HttpUtils.httpGet(QueryToolUrlConstant.FILE_IMAGE_GET, params, headers));
    }

}
