package ppos

import (
	"PPOSUtils/utils"
)

//NewJwtWxOpen 令牌：账号/账号类型
func NewJwtWx() *wtWx {
	return &wtWx{}
}

//JwtAccount
type wtWx struct {
	JwtBase
}

func (that *wtWx) init() {
	if that.paramsMp == nil {
		that.JwtBase.init()
		that.paramsSlice = append(that.paramsSlice, "account_type")
		that.paramsSlice = append(that.paramsSlice, "account_id")
		that.paramsSlice = append(that.paramsSlice, "member_id")
		that.paramsSlice = append(that.paramsSlice, "company_id")
	}
}

func (that *wtWx) SetAccountType(accountType interface{}) {
	that.init()
	that.paramsMp.Set("account_type", accountType)
}

func (that *wtWx) SetAccountID(accountID int64) {
	that.init()
	that.paramsMp.Set("account_id", accountID)
}

func (that *wtWx) SetCompanyID(companyID int64) {
	that.init()
	that.paramsMp.Set("company_id", companyID)
}

func (that *wtWx) SetMemberID(memberID int64) {
	that.init()
	that.paramsMp.Set("member_id", memberID)
}

//生成应用令牌
func (that *wtWx) CreateJwt(params ...utils.Mp) (string, error) {
	//
	that.init()
	_jwtString, _err := that.JwtBase.CreateJwt(params...)
	if _err != nil {
		return "", _err
	}
	return _jwtString, nil
}

func (that *wtWx) ParseParams() (utils.Mp, error) {
	//
	that.init()
	if _, _err := that.JwtBase.ParseParams(); _err != nil {
		return nil, _err
	}
	return that.paramsMp, nil
}
