package im

import (
	"encoding/json"
	"gitlab.fjmaimaimai.com/mmm-go/partner/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
}