using Topsdk.Top.Defaultability.Request;
using Topsdk.Top.Defaultability.Response;
using Topsdk.Util;

namespace Topsdk.Top.Defaultability;


public class Defaultability
{

    private ITopApiClient topApiClient;

    public Defaultability(ITopApiClient topApiClient)
    {
        this.topApiClient = topApiClient;
    }

    /*
        淘宝客-推广者-万能转链
        taobao.tbk.dg.general.link.convert
    */
    public TaobaoTbkDgGeneralLinkConvertResponse TaobaoTbkDgGeneralLinkConvert(TaobaoTbkDgGeneralLinkConvertRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgGeneralLinkConvertResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        关键词过滤匹配
        taobao.kfc.keyword.search
    */
    public TaobaoKfcKeywordSearchResponse TaobaoKfcKeywordSearch(TaobaoKfcKeywordSearchRequest request,String session)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam(),session);
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoKfcKeywordSearchResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-淘口令预警及拦截查询
        taobao.tbk.dg.tpwd.risk.report
    */
    public TaobaoTbkDgTpwdRiskReportResponse TaobaoTbkDgTpwdRiskReport(TaobaoTbkDgTpwdRiskReportRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgTpwdRiskReportResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-物料id列表查询
        taobao.tbk.optimus.tou.material.ids.get
    */
    public TaobaoTbkOptimusTouMaterialIdsGetResponse TaobaoTbkOptimusTouMaterialIdsGet(TaobaoTbkOptimusTouMaterialIdsGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkOptimusTouMaterialIdsGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-物料搜索升级版
        taobao.tbk.dg.material.optional.upgrade
    */
    public TaobaoTbkDgMaterialOptionalUpgradeResponse TaobaoTbkDgMaterialOptionalUpgrade(TaobaoTbkDgMaterialOptionalUpgradeRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgMaterialOptionalUpgradeResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-物料精选升级版
        taobao.tbk.dg.material.recommend
    */
    public TaobaoTbkDgMaterialRecommendResponse TaobaoTbkDgMaterialRecommend(TaobaoTbkDgMaterialRecommendRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgMaterialRecommendResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

    public ITopApiClient TopApiClient
    {
        get => topApiClient;
        set => topApiClient = value ?? throw new ArgumentNullException(nameof(value));
    }
}
