package ppos

import (
	"PPOSUtils/utils"
)

//NewJwtAccount 令牌：账号/账号类型
func NewJwtAccount() *JwtAccount {
	return &JwtAccount{}
}

//JwtAccount
type JwtAccount struct {
	JwtBase
}

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

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

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

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

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