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

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

// V1CamelOilTokenColumns defines and stores column names for the table camel_oil_token.
type V1CamelOilTokenColumns struct {
	Id                  string // 主键ID
	UserId              string // 用户ID，空字符串表示管理员创建
	Name                string // 名称
	Phone               string // 绑定的手机号
	Status              string // 状态：0待验证码 1可用 2已禁用 3已过期 4登录失败
	LoginToken          string // 登录后获取的token
	LoginTokenExpiresAt string // 登录token过期时间
	LastLoginAt         string // 最后登录时间
	BindCount           string // 已绑定卡密数量
	TotalBindAmount     string // 累计绑定金额
	LastBindAt          string // 最后绑定时间
	LastUsedAt          string // 最后使用时间
	Remark              string // 备注
	CreatedAt           string // 创建时间
	UpdatedAt           string // 更新时间
	DeletedAt           string // 删除时间（软删除）
	RechargeLimitAmount string // 充值金额限制
	RechargeLimitCount  string // 充值次数限制
	TotalRechargeAmount string // 总充值金额
}

// v1CamelOilTokenColumns holds the columns for the table camel_oil_token.
var v1CamelOilTokenColumns = V1CamelOilTokenColumns{
	Id:                  "id",
	UserId:              "user_id",
	Name:                "name",
	Phone:               "phone",
	Status:              "status",
	LoginToken:          "login_token",
	LoginTokenExpiresAt: "login_token_expires_at",
	LastLoginAt:         "last_login_at",
	BindCount:           "bind_count",
	TotalBindAmount:     "total_bind_amount",
	LastBindAt:          "last_bind_at",
	LastUsedAt:          "last_used_at",
	Remark:              "remark",
	CreatedAt:           "created_at",
	UpdatedAt:           "updated_at",
	DeletedAt:           "deleted_at",
	RechargeLimitAmount: "recharge_limit_amount",
	RechargeLimitCount:  "recharge_limit_count",
	TotalRechargeAmount: "total_recharge_amount",
}

// NewV1CamelOilTokenDao creates and returns a new DAO object for table data access.
func NewV1CamelOilTokenDao(handlers ...gdb.ModelHandler) *V1CamelOilTokenDao {
	return &V1CamelOilTokenDao{
		group:    "default",
		table:    "camel_oil_token",
		columns:  v1CamelOilTokenColumns,
		handlers: handlers,
	}
}

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

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

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

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