// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.

package models

import (
	"context"
	"time"

	"quyun/v2/pkg/consts"

	"go.ipao.vip/gen"
)

const TableNameUserCoupon = "user_coupons"

// UserCoupon mapped from table <user_coupons>
type UserCoupon struct {
	ID        int64                   `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
	UserID    int64                   `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
	CouponID  int64                   `gorm:"column:coupon_id;type:bigint;not null" json:"coupon_id"`
	OrderID   int64                   `gorm:"column:order_id;type:bigint" json:"order_id"`
	Status    consts.UserCouponStatus `gorm:"column:status;type:character varying(32);not null;default:unused" json:"status"`
	UsedAt    time.Time               `gorm:"column:used_at;type:timestamp with time zone" json:"used_at"`
	CreatedAt time.Time               `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
}

// Quick operations without importing query package
// Update applies changed fields to the database using the default DB.
func (m *UserCoupon) Update(ctx context.Context) (gen.ResultInfo, error) {
	return Q.UserCoupon.WithContext(ctx).Updates(m)
}

// Save upserts the model using the default DB.
func (m *UserCoupon) Save(ctx context.Context) error { return Q.UserCoupon.WithContext(ctx).Save(m) }

// Create inserts the model using the default DB.
func (m *UserCoupon) Create(ctx context.Context) error {
	return Q.UserCoupon.WithContext(ctx).Create(m)
}

// Delete removes the row represented by the model using the default DB.
func (m *UserCoupon) Delete(ctx context.Context) (gen.ResultInfo, error) {
	return Q.UserCoupon.WithContext(ctx).Delete(m)
}

// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
func (m *UserCoupon) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
	return Q.UserCoupon.WithContext(ctx).Unscoped().Delete(m)
}

// Reload reloads the model from database by its primary key and overwrites current fields.
func (m *UserCoupon) Reload(ctx context.Context) error {
	fresh, err := Q.UserCoupon.WithContext(ctx).GetByID(m.ID)
	if err != nil {
		return err
	}
	*m = *fresh
	return nil
}
