package services

import (
	"github.com/gogf/gf/util/guid"
	"sparrow/pkg/models"
	"sparrow/services/knowoapi/model"
)

// RoleService role manager
type RoleService interface {
	Create(*models.Role) error
	Delete(*models.Role) error
	Update(*models.Role) error
	QueryAll(int, int, string) ([]models.Role, int, error)
	QueryRole(int) (models.Role, error)
}

type roleService struct {
	models *model.All
}

// NewRoleService new role manager
func NewRoleService(models *model.All) RoleService {
	return roleService{
		models: models,
	}
}

func (a roleService) Create(role *models.Role) error {
	role.RecordId = guid.S()
	return a.models.Role.Create(role)
}

func (a roleService) Delete(role *models.Role) error {
	return a.models.Role.Delete(role)
}

func (a roleService) Update(role *models.Role) error {
	return a.models.Role.Update(role)
}

func (a roleService) QueryAll(pi, ps int, name string) ([]models.Role, int, error) {
	return a.models.Role.QueryAll(pi, ps, name)
}

func (a roleService) QueryRole(roleid int) (models.Role, error) {
	return a.models.Role.QueryRole(roleid)
}
