package authz

import (
	"strings"

	"git.rosy.net.cn/baseapi/utils"
)

const (
	StoreRoleBoss = "StoreBoss"

	RoleNameSep     = "/"
	RolePrefix      = "Role"
	StoreRolePrefix = "Store"
)

type RoleInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	StoreID     int    `json:"storeID,omitempty"` // 如果这个值非0，表示门店角色
}

var (
	StoreRoleDescriptionMap = map[string]string{
		StoreRoleBoss: "门店老板",
	}
	StoreRoleList = []*RoleInfo{
		&RoleInfo{
			Name:        StoreRoleBoss,
			Description: StoreRoleDescriptionMap[StoreRoleBoss],
		},
	}
)

type IAuthz interface {
	AddRole4User(userID string, r *RoleInfo) (err error)
	DeleteRole4User(userID string, r *RoleInfo) (err error)
	GetUserRoleList(userID string) (roleList []*RoleInfo, err error)
	GetRoleUserList(r *RoleInfo) (userIDList []string, err error)
	// GetAllRoleList() (roleList []*RoleInfo)
}

func (r *RoleInfo) GetFullName() (fullRoleName string) {
	strList := []string{
		RolePrefix,
		r.Name,
	}
	if r.StoreID > 0 {
		strList = append(strList, StoreRolePrefix, utils.Int2Str(r.StoreID))
	} else if r.StoreID != 0 {
		strList = append(strList, StoreRolePrefix, "")
	}
	fullRoleName = strings.Join(strList, RoleNameSep)
	return fullRoleName
}
