// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================

package internal

import (
	"context"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

// V1SysUserDao is the data access object for the table sys_user.
type V1SysUserDao struct {
	table    string             // table is the underlying table name of the DAO.
	group    string             // group is the database configuration group name of the current DAO.
	columns  V1SysUserColumns   // columns contains all the column names of Table for convenient usage.
	handlers []gdb.ModelHandler // handlers for customized model modification.
}

// V1SysUserColumns defines and stores column names for the table sys_user.
type V1SysUserColumns struct {
	Id           string // ID
	Username     string // 账号
	NickName     string // 昵称
	UserPassword string // 密码
	IsAdmin      string // 是否是管理员
	UserSalt     string //
	UserStatus   string // 用户状态
	OtpKey       string //
	OtpSecret    string //
	CreatedAt    string //
	UpdatedAt    string //
	DeletedAt    string //
}

// v1SysUserColumns holds the columns for the table sys_user.
var v1SysUserColumns = V1SysUserColumns{
	Id:           "id",
	Username:     "username",
	NickName:     "nick_name",
	UserPassword: "user_password",
	IsAdmin:      "is_admin",
	UserSalt:     "user_salt",
	UserStatus:   "user_status",
	OtpKey:       "otp_key",
	OtpSecret:    "otp_secret",
	CreatedAt:    "created_at",
	UpdatedAt:    "updated_at",
	DeletedAt:    "deleted_at",
}

// NewV1SysUserDao creates and returns a new DAO object for table data access.
func NewV1SysUserDao(handlers ...gdb.ModelHandler) *V1SysUserDao {
	return &V1SysUserDao{
		group:    "default",
		table:    "sys_user",
		columns:  v1SysUserColumns,
		handlers: handlers,
	}
}

// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *V1SysUserDao) DB() gdb.DB {
	return g.DB(dao.group)
}

// Table returns the table name of the current DAO.
func (dao *V1SysUserDao) Table() string {
	return dao.table
}

// Columns returns all column names of the current DAO.
func (dao *V1SysUserDao) Columns() V1SysUserColumns {
	return dao.columns
}

// Group returns the database configuration group name of the current DAO.
func (dao *V1SysUserDao) Group() string {
	return dao.group
}

// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *V1SysUserDao) Ctx(ctx context.Context) *gdb.Model {
	model := dao.DB().Model(dao.table)
	for _, handler := range dao.handlers {
		model = handler(model)
	}
	return model.Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *V1SysUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
