// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.17.8
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// UsersUpdateFields 修改前台用户表字段过滤
type UsersUpdateFields struct {
	Phone     string `json:"phone"     dc:"手机号"`
	Nickname  string `json:"nickname"  dc:"昵称"`
	Email     string `json:"email"     dc:"邮箱"`
	Avatar    string `json:"avatar"    dc:"头像URL"`
	Introduce string `json:"introduce" dc:"个人简介"`
	Realname  string `json:"realname"  dc:"真实姓名"`
	Gender    int    `json:"gender"    dc:"性别"`
	Birthday  string `json:"birthday"  dc:"生日"`
	School    string `json:"school"    dc:"学校"`
	Grade     string `json:"grade"     dc:"学历"`
	Major     string `json:"major"     dc:"专业"`
	Status    int    `json:"status"    dc:"用户状态"`
}

// UsersInsertFields 新增前台用户表字段过滤
type UsersInsertFields struct {
	Phone     string `json:"phone"     dc:"手机号"`
	Nickname  string `json:"nickname"  dc:"昵称"`
	Email     string `json:"email"     dc:"邮箱"`
	Avatar    string `json:"avatar"    dc:"头像URL"`
	Introduce string `json:"introduce" dc:"个人简介"`
	Realname  string `json:"realname"  dc:"真实姓名"`
	Gender    int    `json:"gender"    dc:"性别"`
	Birthday  string `json:"birthday"  dc:"生日"`
	School    string `json:"school"    dc:"学校"`
	Grade     string `json:"grade"     dc:"学历"`
	Major     string `json:"major"     dc:"专业"`
	Status    int    `json:"status"    dc:"用户状态"`
}

// UsersEditInp 修改/新增前台用户表
type UsersEditInp struct {
	entity.Users
}

func (in *UsersEditInp) Filter(ctx context.Context) (err error) {
	// 验证邮箱
	if err := g.Validator().Rules("email").Data(in.Email).Messages("邮箱不是邮箱地址").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type UsersEditModel struct{}

// UsersDeleteInp 删除前台用户表
type UsersDeleteInp struct {
	Id interface{} `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *UsersDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type UsersDeleteModel struct{}

// UsersViewInp 获取指定前台用户表信息
type UsersViewInp struct {
	Id int `json:"id" v:"required#id不能为空" dc:"id"`
}

func (in *UsersViewInp) Filter(ctx context.Context) (err error) {
	return
}

type UsersViewModel struct {
	entity.Users
}

// UsersListInp 获取前台用户表列表
type UsersListInp struct {
	form.PageReq
	Id        int           `json:"id"        dc:"id"`
	Status    int           `json:"status"    dc:"用户状态"`
	CreatedAt []*gtime.Time `json:"createdAt" dc:"注册时间"`
}

func (in *UsersListInp) Filter(ctx context.Context) (err error) {
	return
}

type UsersListModel struct {
	Id                int         `json:"id"                dc:"id"`
	Phone             string      `json:"phone"             dc:"手机号"`
	Nickname          string      `json:"nickname"          dc:"昵称"`
	Email             string      `json:"email"             dc:"邮箱"`
	Avatar            string      `json:"avatar"            dc:"头像URL"`
	Password          string      `json:"password"          dc:"密码"`
	Salt              string      `json:"salt"              dc:"密码盐"`
	Realname          string      `json:"realname"          dc:"真实姓名"`
	Gender            int         `json:"gender"            dc:"性别"`
	Birthday          string      `json:"birthday"          dc:"生日"`
	School            string      `json:"school"            dc:"学校"`
	Grade             string      `json:"grade"             dc:"学历"`
	Major             string      `json:"major"             dc:"专业"`
	Status            int         `json:"status"            dc:"用户状态"`
	VerificationToken string      `json:"verificationToken" dc:"邮箱验证令牌"`
	EmailVerified     int         `json:"emailVerified"     dc:"邮箱验证状态"`
	CreatedAt         *gtime.Time `json:"createdAt"         dc:"注册时间"`
	LastLogin         *gtime.Time `json:"lastLogin"         dc:"最后登录时间"`
	LoginCount        int         `json:"loginCount"        dc:"累计登录次数"`
}

// UsersExportModel 导出前台用户表
type UsersExportModel struct {
	Id                int         `json:"id"                dc:"id"`
	Phone             string      `json:"phone"             dc:"手机号"`
	Nickname          string      `json:"nickname"          dc:"昵称"`
	Email             string      `json:"email"             dc:"邮箱"`
	Avatar            string      `json:"avatar"            dc:"头像URL"`
	Password          string      `json:"password"          dc:"密码"`
	Salt              string      `json:"salt"              dc:"密码盐"`
	Realname          string      `json:"realname"          dc:"真实姓名"`
	Gender            int         `json:"gender"            dc:"性别"`
	Birthday          string      `json:"birthday"          dc:"生日"`
	School            string      `json:"school"            dc:"学校"`
	Grade             string      `json:"grade"             dc:"学历"`
	Major             string      `json:"major"             dc:"专业"`
	Status            int         `json:"status"            dc:"用户状态"`
	VerificationToken string      `json:"verificationToken" dc:"邮箱验证令牌"`
	EmailVerified     int         `json:"emailVerified"     dc:"邮箱验证状态"`
	CreatedAt         *gtime.Time `json:"createdAt"         dc:"注册时间"`
	LastLogin         *gtime.Time `json:"lastLogin"         dc:"最后登录时间"`
	LoginCount        int         `json:"loginCount"        dc:"累计登录次数"`
}

// UsersStatusInp 更新前台用户表状态
type UsersStatusInp struct {
	Id     int `json:"id" v:"required#id不能为空" dc:"id"`
	Status int `json:"status" dc:"状态"`
}

func (in *UsersStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("id不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type UsersStatusModel struct{}