package models

import (
	"fmt"

	"easydo-echo_win7/utils"
)

// User 用户模型
type SysUser struct {
	ID       *int64  `json:"id" db:"id" id_type:"AUTO"`
	DeptId   *int64  `json:"deptId" db:"dept_id"`
	NickName *string `json:"nickName" db:"nick_name"`
	Gender   *string `json:"gender" db:"gender"`
	Phone    *string `json:"phone" db:"phone"`
	Username *string `json:"username"  db:"username"`
	Password *string `json:"-" db:"password"` // 不序列化密码
	Email    *string `json:"email" db:"email"`
	Features *string `json:"features" db:"features"`
	TenantId *string `json:"tenantId" db:"tenant_id"`

	Dept       *SysDept   `json:"dept" db:"-"`
	Tenant     *Tenant    `json:"tenant" db:"-"`
	RoleList   *[]SysRole `json:"roleList" db:"-"`
	EmptyField *[]string  `json:"emptyField" db:"-"`
}

// CheckPassword 验证密码
func (u *SysUser) CheckPassword(password string) bool {
	plainText, err := utils.DecryptByPrivateKey(password)
	if err != nil {
		fmt.Printf("解密失败: %v\n", err)
		return false
	}
	fmt.Printf("解密结果: %s\n", plainText)
	result := utils.VerifyPassword(plainText, *u.Password)

	return result
}

// UserLoginRequest 登录请求
type UserLoginRequest struct {
	Username    string `json:"username" validate:"required,min=3,max=50"`
	Password    string `json:"password" validate:"required,min=6,max=100"`
	CaptchaID   string `json:"uuid" validate:"required"`
	CaptchaCode string `json:"code" validate:"required"`
}
