package gd_vehicle

import (
	"context"
	"time"

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

type GdVehicleXClient struct {
	xcli client.XClient
}

func (a *GdVehicleXClient) Init(etcdAddrs []string, basePath, servicePath string) {
	opt := client.Option{
		Retries:        1,
		RPCPath:        share.DefaultRPCPath,
		ConnectTimeout: 10 * time.Second,
		SerializeType:  protocol.JSON,
		CompressType:   protocol.None,
		BackupLatency:  10 * time.Millisecond,
	}
	d := client.NewPeer2PeerDiscovery("tcp@"+"management:60004", "")
	//d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
	a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
}

func (a *GdVehicleXClient) VehicleGetConfiguration(ctx context.Context, req *VehicleGetConfigurationReq) (reply VehicleGetConfigurationReply, err error) {
	err = a.xcli.Call(ctx, "VehicleGetConfiguration", req, &reply)
	return
}
func (a *GdVehicleXClient) VehicleGetStyle(ctx context.Context, req *VehicleGetStyleReq) (reply VehicleGetStyleReply, err error) {
	err = a.xcli.Call(ctx, "VehicleGetStyle", req, &reply)
	return
}
func (a *GdVehicleXClient) VehicleGetInfo(ctx context.Context, req *VehicleGetInfoReq) (reply VehicleGetInfoReply, err error) {
	err = a.xcli.Call(ctx, "VehicleGetInfo", req, &reply)
	return
}

func (a *GdVehicleXClient) VechicleVerifyOwner(ctx context.Context, req *VechicleVerifyOwnerReq) (reply VechicleVerifyOwnerReply, err error) {
	err = a.xcli.Call(ctx, "VechicleVerifyOwner", req, &reply)
	return
}

func (a *GdVehicleXClient) VehicleGetBrandInfo(ctx context.Context, req *VehicleGetBrandInfoReq) (reply VehicleGetBrandInfoReply, err error) {
	err = a.xcli.Call(ctx, "VehicleGetBrandInfo", req, &reply)
	return
}
