package ppos

import (
	"PPOSUtils/utils"
)

//NewJwtCompany 令牌：B端应用中心
func NewJwtCompany() *JwtCompany {
	return &JwtCompany{}
}

type JwtCompany struct {
	JwtAccount
}

func (that *JwtCompany) init() {
	if that.paramsMp == nil {
		that.JwtAccount.init()
		that.paramsSlice = append(that.paramsSlice, "company_id")
		that.paramsSlice = append(that.paramsSlice, "personnel_id")
	}
}

//公司ID
func (that *JwtCompany) SetCompanyID(companyID int64) {
	that.init()
	that.paramsMp.Set("company_id", companyID)
}

//员工ID
func (that *JwtCompany) SetPersonnelID(personnelID int64) {
	that.init()
	that.paramsMp.Set("personnel_id", personnelID)
}

//部门ID
func (that *JwtCompany) SetBranchID(branchID int64) {
	that.init()
	that.paramsMp.Set("branch_id", branchID)
}

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

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