// 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 TableNameNotification = "notifications"

// Notification mapped from table <notifications>
type Notification 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"`
	TenantID  int64     `gorm:"column:tenant_id;type:bigint" json:"tenant_id"`
	Type      string    `gorm:"column:type;type:character varying(32);not null" json:"type"`
	Title     string    `gorm:"column:title;type:character varying(255);not null" json:"title"`
	Content   string    `gorm:"column:content;type:text;not null" json:"content"`
	IsRead    bool      `gorm:"column:is_read;type:boolean" json:"is_read"`
	CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
}

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

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

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

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

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

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