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

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

// UserPointsLogsColumns defines and stores column names for the table user_points_logs.
type UserPointsLogsColumns struct {
	Id             string // 积分流水ID
	UserId         string // 用户ID
	ChangeType     string // 变动类型，1=消费(spend), 2=收入(earn)
	PointsChange   string // 积分变化数，正数增加，负数减少
	RelatedOrderId string // 关联ID：当change_type=1时，为chapter_purchases.id；当change_type=2时，为advertisement_records.id
	Description    string // 变动说明
	CreatedAt      string // 变动时间
}

// userPointsLogsColumns holds the columns for the table user_points_logs.
var userPointsLogsColumns = UserPointsLogsColumns{
	Id:             "id",
	UserId:         "user_id",
	ChangeType:     "change_type",
	PointsChange:   "points_change",
	RelatedOrderId: "related_order_id",
	Description:    "description",
	CreatedAt:      "created_at",
}

// NewUserPointsLogsDao creates and returns a new DAO object for table data access.
func NewUserPointsLogsDao(handlers ...gdb.ModelHandler) *UserPointsLogsDao {
	return &UserPointsLogsDao{
		group:    "default",
		table:    "user_points_logs",
		columns:  userPointsLogsColumns,
		handlers: handlers,
	}
}

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

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

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

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