package role

import "time"

// 角色实体
type Role struct {
	// dcc
	Id int64 `json:"id"`
	// 角色名称
	RoleName string `json:"roleName"`
	// 父级Id
	ParentId int64 `json:"parentId"`
	// 创建时间
	CreateTime time.Time `json:"createTime"`
	// 更新时间
	UpdateTime time.Time `json:"updateTime"`
}

type RoleRepository interface {
	Save(role *Role) (*Role, error)
	Remove(role *Role) (*Role, error)
	FindOne(queryOptions map[string]interface{}) (*Role, error)
	Find(queryOptions map[string]interface{}) (int64, []*Role, error)
}

func (role *Role) Identify() interface{} {
	if role.Id == 0 {
		return nil
	}
	return role.Id
}

func (role *Role) Update(data map[string]interface{}) error {
	if Id, ok := data["Id"]; ok {
		role.Id = Id.(int64)
	}
	if RoleName, ok := data["RoleName"]; ok {
		role.RoleName = RoleName.(string)
	}
	if ParentId, ok := data["ParentId"]; ok {
		role.ParentId = ParentId.(int64)
	}
	if CreateTime, ok := data["CreateTime"]; ok {
		role.CreateTime = CreateTime.(time.Time)
	}
	if UpdateTime, ok := data["UpdateTime"]; ok {
		role.UpdateTime = UpdateTime.(time.Time)
	}
	return nil
}