// 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"
	"gorm.io/gorm"
)

const TableNameContent = "contents"

// Content mapped from table <contents>
type Content struct {
	ID                  int64                    `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID：自增；用于内容引用" json:"id"`                                                                      // 主键ID：自增；用于内容引用
	TenantID            int64                    `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID：多租户隔离关键字段；所有查询/写入必须限定 tenant_id" json:"tenant_id"`                                                       // 租户ID：多租户隔离关键字段；所有查询/写入必须限定 tenant_id
	UserID              int64                    `gorm:"column:user_id;type:bigint;not null;comment:用户ID：内容创建者/发布者；用于权限与审计（例如私有内容仅作者可见）" json:"user_id"`                                                            // 用户ID：内容创建者/发布者；用于权限与审计（例如私有内容仅作者可见）
	Title               string                   `gorm:"column:title;type:character varying(255);not null;comment:标题：用于列表展示与搜索；建议限制长度（由业务校验）" json:"title"`                                                         // 标题：用于列表展示与搜索；建议限制长度（由业务校验）
	Description         string                   `gorm:"column:description;type:text;not null;comment:描述：用于详情页展示；可为空字符串" json:"description"`                                                                        // 描述：用于详情页展示；可为空字符串
	Status              consts.ContentStatus     `gorm:"column:status;type:character varying(32);not null;default:draft;comment:状态：draft/reviewing/published/unpublished/blocked；published 才对外展示" json:"status"`    // 状态：draft/reviewing/published/unpublished/blocked；published 才对外展示
	Visibility          consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only;comment:可见性：public/tenant_only/private；仅控制详情可见，正片资源仍需按价格/权益校验" json:"visibility"` // 可见性：public/tenant_only/private；仅控制详情可见，正片资源仍需按价格/权益校验
	PreviewSeconds      int32                    `gorm:"column:preview_seconds;type:integer;not null;default:60;comment:试看秒数：默认 60；只对 preview 资源生效；必须为正整数" json:"preview_seconds"`                                  // 试看秒数：默认 60；只对 preview 资源生效；必须为正整数
	PreviewDownloadable bool                     `gorm:"column:preview_downloadable;type:boolean;not null;comment:试看是否允许下载：默认 false；当前策略固定为不允许下载（仅 streaming）" json:"preview_downloadable"`                         // 试看是否允许下载：默认 false；当前策略固定为不允许下载（仅 streaming）
	PublishedAt         time.Time                `gorm:"column:published_at;type:timestamp with time zone;comment:发布时间：首次发布时写入；用于时间窗与排序" json:"published_at"`                                                       // 发布时间：首次发布时写入；用于时间窗与排序
	DeletedAt           gorm.DeletedAt           `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间：非空表示已删除；对外接口需过滤" json:"deleted_at"`                                                           // 软删除时间：非空表示已删除；对外接口需过滤
	CreatedAt           time.Time                `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间：默认 now()；用于审计与排序" json:"created_at"`                                    // 创建时间：默认 now()；用于审计与排序
	UpdatedAt           time.Time                `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间：默认 now()；编辑内容时写入" json:"updated_at"`                                    // 更新时间：默认 now()；编辑内容时写入
}

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

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

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

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

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

// Restore sets deleted_at to NULL for this model's primary key using the default DB.
func (m *Content) Restore(ctx context.Context) (gen.ResultInfo, error) {
	return Q.Content.WithContext(ctx).RestoreByID(m.ID)
}

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