// ==========================================================================
// 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"
)

// V1UserInfoDao is the data access object for the table user_info.
type V1UserInfoDao 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  V1UserInfoColumns  // columns contains all the column names of Table for convenient usage.
	handlers []gdb.ModelHandler // handlers for customized model modification.
}

// V1UserInfoColumns defines and stores column names for the table user_info.
type V1UserInfoColumns struct {
	Id         string // 主键，自增
	UserId     string // 用户登录号
	Passwd     string // 用户登录密码
	Nick       string // 用户昵称
	Remark     string // 备注
	Ip         string // 用户当前ip
	Status     string // 该用户的状态 active、unactive、delete
	Role       string // 管理者分配的角色
	RoleName   string // 操作员分配的角色名称
	OtpSecret  string //
	OtpKey     string //
	CreateTime string // 创建时间
	UpdateTime string // 最后一次修改时间
}

// v1UserInfoColumns holds the columns for the table user_info.
var v1UserInfoColumns = V1UserInfoColumns{
	Id:         "id",
	UserId:     "user_id",
	Passwd:     "passwd",
	Nick:       "nick",
	Remark:     "remark",
	Ip:         "ip",
	Status:     "status",
	Role:       "role",
	RoleName:   "role_name",
	OtpSecret:  "otp_secret",
	OtpKey:     "otp_key",
	CreateTime: "create_time",
	UpdateTime: "update_time",
}

// NewV1UserInfoDao creates and returns a new DAO object for table data access.
func NewV1UserInfoDao(handlers ...gdb.ModelHandler) *V1UserInfoDao {
	return &V1UserInfoDao{
		group:    "default",
		table:    "user_info",
		columns:  v1UserInfoColumns,
		handlers: handlers,
	}
}

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

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

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

// Group returns the database configuration group name of the current DAO.
func (dao *V1UserInfoDao) 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 *V1UserInfoDao) 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 *V1UserInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
