package im

import (
	"encoding/json"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
)

func init() {
	InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET)
}

type RequestParam interface {
	Format() map[string]string
	GetPath() string
	Valid() error
}

//接口
func CallCreate(v UserCreate) (*UserTokenResult, error) {
	var result UserTokenResult
	btData, err := DefaultImClient.Call(v)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(btData, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}
func CallRefreshToken(v UserRefreshToken) (*UserTokenResult, error) {
	var result UserTokenResult
	btData, err := DefaultImClient.Call(v)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(btData, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}
func CallUpdate(v UserUpdate) (*BaseResp, error) {
	var result BaseResp
	btData, err := DefaultImClient.Call(v)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(btData, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}

/*CheckIm */
type CheckImRequest struct {
	UserId       int64
	ImId         string
	Uname        string
	Icon         string
	CustomerImId string
	IsCreated    bool
}
type CheckImResponse struct {
	ImToken   string //net im token
	CsAccount int64  //客服id
}