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

	"go.ipao.vip/gen"
)

const TableNameTenantInvite = "tenant_invites"

// TenantInvite mapped from table <tenant_invites>
type TenantInvite struct {
	ID                     int64     `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
	TenantID               int64     `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
	UserID                 int64     `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
	Code                   string    `gorm:"column:code;type:character varying(64);not null" json:"code"`
	Status                 string    `gorm:"column:status;type:character varying(32);default:active" json:"status"`
	MaxUses                int32     `gorm:"column:max_uses;type:integer;not null" json:"max_uses"`
	UsedCount              int32     `gorm:"column:used_count;type:integer" json:"used_count"`
	ExpiresAt              time.Time `gorm:"column:expires_at;type:timestamp with time zone" json:"expires_at"`
	DisabledAt             time.Time `gorm:"column:disabled_at;type:timestamp with time zone" json:"disabled_at"`
	DisabledOperatorUserID int64     `gorm:"column:disabled_operator_user_id;type:bigint" json:"disabled_operator_user_id"`
	Remark                 string    `gorm:"column:remark;type:character varying(255)" json:"remark"`
	CreatedAt              time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
	UpdatedAt              time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
}

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

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

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

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

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

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