// Copyright 2019  getensh.com. All rights reserved.
// Use of this source code is governed by  getensh.com.

/*
	package gd_access_log 是日志查询类微服务client
*/
package gd_statistics

import (
	"context"
	"fmt"
	"time"

	"github.com/smallnest/rpcx/client"
	"github.com/smallnest/rpcx/protocol"
	"github.com/smallnest/rpcx/share"
)

type GdStatisticsXClient struct {
	xcli client.XClient
}

func (a *GdStatisticsXClient) Init(etcdAddrs []string, basePath, servicePath string) {
	opt := client.Option{
		Retries:        3,
		RPCPath:        share.DefaultRPCPath,
		ConnectTimeout: 10 * time.Second,
		SerializeType:  protocol.JSON,
		CompressType:   protocol.None,
		BackupLatency:  10 * time.Millisecond,
	}

	d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
	a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)

}

func (a *GdStatisticsXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort string) {
	opt := client.Option{
		Retries:        1,
		RPCPath:        share.DefaultRPCPath,
		ConnectTimeout: 10 * time.Second,
		SerializeType:  protocol.JSON,
		CompressType:   protocol.None,
		BackupLatency:  10 * time.Millisecond,
	}
	sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", k8sServiceName, k8sServicePort), "")
	a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt)
}

func (a *GdStatisticsXClient) LogQueryAccessLog(ctx context.Context, req *LogQueryAccessLogReq) (reply LogQueryAccessLogReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryAccessLog", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogExport(ctx context.Context, req *LogQueryAccessLogReq) (reply LogQueryAccessLogReply, err error) {
	err = a.xcli.Call(ctx, "LogExport", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryThirdpartAccessLog(ctx context.Context, req *LogQueryThirdpartAccessLogReq) (reply LogQueryThirdpartAccessLogReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryThirdpartAccessLog", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryAccessLogCount(ctx context.Context, req *LogQueryAccessLogCountReq) (reply LogQueryAccessLogCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryAccessLogCount", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryThirdpartAccessLogCount(ctx context.Context, req *LogQueryThirdpartAccessLogCountReq) (reply LogQueryThirdpartAccessLogCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryThirdpartAccessLogCount", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryAccessLogThirdpartLog(ctx context.Context, req *LogQueryAccessLogThirdpartLogReq) (reply LogQueryAccessLogThirdpartLogReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryAccessLogThirdpartLog", req, &reply)
	return
}

// 访问日志用户统计报表
func (a *GdStatisticsXClient) LogQueryUserAccessCount(ctx context.Context, req *LogQueryUserAccessCountReq) (reply LogQueryUserAccessCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryUserAccessCount", req, &reply)
	return
}

// 访问日志用户统计报表导出
func (a *GdStatisticsXClient) LogQueryUserAccessCountExport(ctx context.Context, req *LogQueryUserAccessCountExportReq) (reply LogQueryUserAccessCountExportReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryUserAccessCountExport", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryProviderCountExport(ctx context.Context, req *LogQueryProviderCountExportReq) (reply LogQueryProviderCountExportReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryProviderCountExport", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogExportCreate(ctx context.Context, req *LogExportCreateReq) (reply LogExportCreateReply, err error) {
	err = a.xcli.Call(ctx, "LogExportCreate", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogExportList(ctx context.Context, req *LogExportListReq) (reply LogExportListReply, err error) {
	err = a.xcli.Call(ctx, "LogExportList", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogExportDelete(ctx context.Context, req *LogExportDeleteReq) (reply LogExportDeleteReply, err error) {
	err = a.xcli.Call(ctx, "LogExportDelete", req, &reply)
	return
}

// 访问日志接口统计详情
func (a *GdStatisticsXClient) LogQueryInterfaceCount(ctx context.Context, req *LogQueryInterfaceCountReq) (reply LogQueryInterfaceCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryInterfaceCount", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryThirdpartAccessCount(ctx context.Context, req *LogQueryThirdpartAccessCountReq) (reply LogQueryThirdpartAccessCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryThirdpartAccessCount", req, &reply)
	return
}

func (a *GdStatisticsXClient) LogQueryThirdpartInterfaceCount(ctx context.Context, req *LogQueryThirdpartInterfaceCountReq) (reply LogQueryThirdpartInterfaceCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryThirdpartInterfaceCount", req, &reply)
	return
}

// 访问日志接口异常分析
func (a *GdStatisticsXClient) LogQueryInterfaceAnalyzeError(ctx context.Context, req *LogQueryInterfaceCountReq) (reply LogQueryInterfaceAnalyzeErrorReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryInterfaceAnalyzeError", req, &reply)
	return
}

// 访问日志接口数据源分析
func (a *GdStatisticsXClient) LogQueryInterfaceThirdPartyCount(ctx context.Context, req *LogQueryInterfaceCountReq) (reply LogQueryInterfaceThirdPartyCountReply, err error) {
	err = a.xcli.Call(ctx, "LogQueryInterfaceThirdPartyCount", req, &reply)
	return
}

// 数据源异常分析
func (a *GdStatisticsXClient) ThirdPartyInterfaceErrorAnalyze(ctx context.Context, req *ThirdPartyInterfaceErrorAnalyzeReq) (reply ThirdPartyInterfaceErrorAnalyzeReply, err error) {
	err = a.xcli.Call(ctx, "ThirdPartyInterfaceErrorAnalyze", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetDash(ctx context.Context, req *BiGetDashReq) (reply BiGetDashReply, err error) {
	err = a.xcli.Call(ctx, "BiGetDash", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetTrend(ctx context.Context, req *BiGetTrendReq) (reply BiGetTrendReply, err error) {
	err = a.xcli.Call(ctx, "BiGetTrend", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderTrend(ctx context.Context, req *BiGetProviderTrendReq) (reply BiGetProviderTrendReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderTrend", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetServiceStatus(ctx context.Context, req *BiGetServiceStatusReq) (reply BiGetServiceStatusReply, err error) {
	err = a.xcli.Call(ctx, "BiGetServiceStatus", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderServiceStatus(ctx context.Context, req *BiGetProviderServiceStatusReq) (reply BiGetProviderServiceStatusReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderServiceStatus", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetReport(ctx context.Context, req *BiGetReportReq) (reply BiGetReportReply, err error) {
	err = a.xcli.Call(ctx, "BiGetReport", req, &reply)
	return
}
func (a *GdStatisticsXClient) BiGetProviderReport(ctx context.Context, req *BiGetProviderReportReq) (reply BiGetProviderReportReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderReport", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetDistribution(ctx context.Context, req *BiGetDistributionReq) (reply BiGetDistributionReply, err error) {
	err = a.xcli.Call(ctx, "BiGetDistribution", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderDistribution(ctx context.Context, req *BiGetProviderDistributionReq) (reply BiGetProviderDistributionReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderDistribution", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetApiServiceConsumeInfo(ctx context.Context, req *BiGetApiServiceConsumeInfoReq) (reply BiGetApiServiceConsumeInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetApiServiceConsumeInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetApiServiceDataInfo(ctx context.Context, req *BiGetApiServiceDataInfoReq) (reply BiGetApiServiceDataInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetApiServiceDataInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetApiServiceFailInfo(ctx context.Context, req *BiGetApiServiceFailInfoReq) (reply BiGetApiServiceFailInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetApiServiceFailInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetApiServiceIncomeInfo(ctx context.Context, req *BiGetApiServiceIncomeInfoReq) (reply BiGetApiServiceIncomeInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetApiServiceIncomeInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderServiceDataInfo(ctx context.Context, req *BiGetProviderServiceDataInfoReq) (reply BiGetProviderServiceDataInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderServiceDataInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderServicePayInfo(ctx context.Context, req *BiGetProviderServicePayInfoReq) (reply BiGetProviderServicePayInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderServicePayInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetProviderServiceFailInfo(ctx context.Context, req *BiGetProviderServiceFailInfoReq) (reply BiGetProviderServiceFailInfoReply, err error) {
	err = a.xcli.Call(ctx, "BiGetProviderServiceFailInfo", req, &reply)
	return
}

func (a *GdStatisticsXClient) BiGetPayDistribution(ctx context.Context, req *BiGetPayDistributionReq) (reply BiGetPayDistributionReply, err error) {
	err = a.xcli.Call(ctx, "BiGetPayDistribution", req, &reply)
	return
}
