package userManagement

import "time"

// User 用户
type User struct {
	ID           int64      `json:"id"`
	Username     string     `json:"username"`
	Email        string     `json:"email"`
	Phone        string     `json:"phone,omitempty"`
	Nickname     string     `json:"nickname,omitempty"`
	Avatar       string     `json:"avatar,omitempty"`
	Status       UserStatus `json:"status"`
	RoleIDs      []int64    `json:"role_ids,omitempty"`
	Roles        []*Role    `json:"roles,omitempty"`
	IsSuperAdmin bool       `json:"is_super_admin"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
	LastLoginAt  *time.Time `json:"last_login_at,omitempty"`
}

// UserStatus 用户状态
type UserStatus string

const (
	UserStatusActive   UserStatus = "active"
	UserStatusInactive UserStatus = "inactive"
	UserStatusBanned   UserStatus = "banned"
)

// Role 角色
type Role struct {
	ID          int64           `json:"id"`
	Name        string          `json:"name"`
	Code        string          `json:"code"`
	Description string          `json:"description,omitempty"`
	Status      RoleStatus      `json:"status"`
	Permissions []*Permission   `json:"permissions,omitempty"`
	CreatedAt   time.Time       `json:"created_at"`
	UpdatedAt   time.Time       `json:"updated_at"`
}

// RoleStatus 角色状态
type RoleStatus string

const (
	RoleStatusActive   RoleStatus = "active"
	RoleStatusInactive RoleStatus = "inactive"
)

// Permission 权限
type Permission struct {
	ID          int64           `json:"id"`
	Name        string          `json:"name"`
	Code        string          `json:"code"`
	Description string          `json:"description,omitempty"`
	Type        PermissionType  `json:"type"`
	ParentID    *int64          `json:"parent_id,omitempty"`
	Children    []*Permission   `json:"children,omitempty"`
	CreatedAt   time.Time       `json:"created_at"`
}

// PermissionType 权限类型
type PermissionType string

const (
	PermissionTypeMenu    PermissionType = "menu"
	PermissionTypeAction  PermissionType = "action"
	PermissionTypeAPI     PermissionType = "api"
)

// Device 设备
type Device struct {
	ID           int64       `json:"id"`
	DeviceID     string      `json:"device_id"`
	DeviceName   string      `json:"device_name"`
	DeviceType   DeviceType  `json:"device_type"`
	DeviceOS     string      `json:"device_os"`
	DeviceBrowser string     `json:"device_browser"`
	IP           string      `json:"ip"`
	Location     string      `json:"location,omitempty"`
	IsTrusted    bool        `json:"is_trusted"`
	IsActive     bool        `json:"is_active"`
	LastActiveAt time.Time   `json:"last_active_at"`
	CreatedAt    time.Time   `json:"created_at"`
	UserID       int64       `json:"user_id"`
}

// DeviceType 设备类型
type DeviceType string

const (
	DeviceTypeDesktop DeviceType = "desktop"
	DeviceTypeMobile  DeviceType = "mobile"
	DeviceTypeTablet  DeviceType = "tablet"
)

// LoginLog 登录日志
type LoginLog struct {
	ID          int64        `json:"id"`
	UserID      int64        `json:"user_id"`
	Username    string       `json:"username"`
	IP          string       `json:"ip"`
	Location    string       `json:"location,omitempty"`
	DeviceID    string       `json:"device_id"`
	DeviceName  string       `json:"device_name"`
	Status      LoginStatus  `json:"status"`
	FailReason  string       `json:"fail_reason,omitempty"`
	LoginMethod string       `json:"login_method"`
	CreatedAt   time.Time    `json:"created_at"`
}

// LoginStatus 登录状态
type LoginStatus int

const (
	LoginStatusFailed  LoginStatus = 0
	LoginStatusSuccess LoginStatus = 1
)

// OperationLog 操作日志
type OperationLog struct {
	ID         int64     `json:"id"`
	UserID     int64     `json:"user_id"`
	Username   string    `json:"username"`
	Action     string    `json:"action"`
	Resource   string    `json:"resource"`
	ResourceID *int64    `json:"resource_id,omitempty"`
	Details    string    `json:"details,omitempty"`
	IP         string    `json:"ip"`
	Status     int       `json:"status"`
	CreatedAt  time.Time `json:"created_at"`
}

// Webhook Webhook 配置
type Webhook struct {
	ID          int64     `json:"id"`
	Name        string    `json:"name"`
	URL         string    `json:"url"`
	Events      []string  `json:"events"`
	Secret      string    `json:"secret,omitempty"`
	IsActive    bool      `json:"is_active"`
	RetryCount  int       `json:"retry_count"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

// Stats 统计信息
type Stats struct {
	TotalUsers      int64 `json:"total_users"`
	ActiveUsers     int64 `json:"active_users"`
	TotalDevices    int64 `json:"total_devices"`
	ActiveDevices   int64 `json:"active_devices"`
	TodayLogins     int64 `json:"today_logins"`
	TodayFailLogins int64 `json:"today_fail_logins"`
}

// Pagination 分页参数
type Pagination struct {
	Page     int `json:"page"`
	PageSize int `json:"page_size"`
}

// PaginatedResponse 分页响应
type PaginatedResponse struct {
	Items    interface{} `json:"items"`
	Total    int64       `json:"total"`
	Page     int         `json:"page"`
	PageSize int         `json:"page_size"`
	Pages    int         `json:"pages"`
}
