// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.

package query

import (
	"context"
	"database/sql"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"kra/internal/data/model"
)

func newGvaAnnouncementsInfo(db *gorm.DB, opts ...gen.DOOption) gvaAnnouncementsInfo {
	_gvaAnnouncementsInfo := gvaAnnouncementsInfo{}

	_gvaAnnouncementsInfo.gvaAnnouncementsInfoDo.UseDB(db, opts...)
	_gvaAnnouncementsInfo.gvaAnnouncementsInfoDo.UseModel(&model.GvaAnnouncementsInfo{})

	tableName := _gvaAnnouncementsInfo.gvaAnnouncementsInfoDo.TableName()
	_gvaAnnouncementsInfo.ALL = field.NewAsterisk(tableName)
	_gvaAnnouncementsInfo.ID = field.NewInt64(tableName, "id")
	_gvaAnnouncementsInfo.CreatedAt = field.NewTime(tableName, "created_at")
	_gvaAnnouncementsInfo.UpdatedAt = field.NewTime(tableName, "updated_at")
	_gvaAnnouncementsInfo.DeletedAt = field.NewField(tableName, "deleted_at")
	_gvaAnnouncementsInfo.Title = field.NewString(tableName, "title")
	_gvaAnnouncementsInfo.Content = field.NewString(tableName, "content")
	_gvaAnnouncementsInfo.UserID = field.NewInt64(tableName, "user_id")
	_gvaAnnouncementsInfo.Attachments = field.NewString(tableName, "attachments")

	_gvaAnnouncementsInfo.fillFieldMap()

	return _gvaAnnouncementsInfo
}

type gvaAnnouncementsInfo struct {
	gvaAnnouncementsInfoDo gvaAnnouncementsInfoDo

	ALL         field.Asterisk
	ID          field.Int64
	CreatedAt   field.Time
	UpdatedAt   field.Time
	DeletedAt   field.Field
	Title       field.String // 公告标题
	Content     field.String // 公告内容
	UserID      field.Int64  // 发布者
	Attachments field.String // 相关附件

	fieldMap map[string]field.Expr
}

func (g gvaAnnouncementsInfo) Table(newTableName string) *gvaAnnouncementsInfo {
	g.gvaAnnouncementsInfoDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

func (g gvaAnnouncementsInfo) As(alias string) *gvaAnnouncementsInfo {
	g.gvaAnnouncementsInfoDo.DO = *(g.gvaAnnouncementsInfoDo.As(alias).(*gen.DO))
	return g.updateTableName(alias)
}

func (g *gvaAnnouncementsInfo) updateTableName(table string) *gvaAnnouncementsInfo {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.CreatedAt = field.NewTime(table, "created_at")
	g.UpdatedAt = field.NewTime(table, "updated_at")
	g.DeletedAt = field.NewField(table, "deleted_at")
	g.Title = field.NewString(table, "title")
	g.Content = field.NewString(table, "content")
	g.UserID = field.NewInt64(table, "user_id")
	g.Attachments = field.NewString(table, "attachments")

	g.fillFieldMap()

	return g
}

func (g *gvaAnnouncementsInfo) WithContext(ctx context.Context) IGvaAnnouncementsInfoDo {
	return g.gvaAnnouncementsInfoDo.WithContext(ctx)
}

func (g gvaAnnouncementsInfo) TableName() string { return g.gvaAnnouncementsInfoDo.TableName() }

func (g gvaAnnouncementsInfo) Alias() string { return g.gvaAnnouncementsInfoDo.Alias() }

func (g gvaAnnouncementsInfo) Columns(cols ...field.Expr) gen.Columns {
	return g.gvaAnnouncementsInfoDo.Columns(cols...)
}

func (g *gvaAnnouncementsInfo) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := g.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (g *gvaAnnouncementsInfo) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 8)
	g.fieldMap["id"] = g.ID
	g.fieldMap["created_at"] = g.CreatedAt
	g.fieldMap["updated_at"] = g.UpdatedAt
	g.fieldMap["deleted_at"] = g.DeletedAt
	g.fieldMap["title"] = g.Title
	g.fieldMap["content"] = g.Content
	g.fieldMap["user_id"] = g.UserID
	g.fieldMap["attachments"] = g.Attachments
}

func (g gvaAnnouncementsInfo) clone(db *gorm.DB) gvaAnnouncementsInfo {
	g.gvaAnnouncementsInfoDo.ReplaceConnPool(db.Statement.ConnPool)
	return g
}

func (g gvaAnnouncementsInfo) replaceDB(db *gorm.DB) gvaAnnouncementsInfo {
	g.gvaAnnouncementsInfoDo.ReplaceDB(db)
	return g
}

type gvaAnnouncementsInfoDo struct{ gen.DO }

type IGvaAnnouncementsInfoDo interface {
	gen.SubQuery
	Debug() IGvaAnnouncementsInfoDo
	WithContext(ctx context.Context) IGvaAnnouncementsInfoDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() IGvaAnnouncementsInfoDo
	WriteDB() IGvaAnnouncementsInfoDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) IGvaAnnouncementsInfoDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) IGvaAnnouncementsInfoDo
	Not(conds ...gen.Condition) IGvaAnnouncementsInfoDo
	Or(conds ...gen.Condition) IGvaAnnouncementsInfoDo
	Select(conds ...field.Expr) IGvaAnnouncementsInfoDo
	Where(conds ...gen.Condition) IGvaAnnouncementsInfoDo
	Order(conds ...field.Expr) IGvaAnnouncementsInfoDo
	Distinct(cols ...field.Expr) IGvaAnnouncementsInfoDo
	Omit(cols ...field.Expr) IGvaAnnouncementsInfoDo
	Join(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo
	LeftJoin(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo
	RightJoin(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo
	Group(cols ...field.Expr) IGvaAnnouncementsInfoDo
	Having(conds ...gen.Condition) IGvaAnnouncementsInfoDo
	Limit(limit int) IGvaAnnouncementsInfoDo
	Offset(offset int) IGvaAnnouncementsInfoDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) IGvaAnnouncementsInfoDo
	Unscoped() IGvaAnnouncementsInfoDo
	Create(values ...*model.GvaAnnouncementsInfo) error
	CreateInBatches(values []*model.GvaAnnouncementsInfo, batchSize int) error
	Save(values ...*model.GvaAnnouncementsInfo) error
	First() (*model.GvaAnnouncementsInfo, error)
	Take() (*model.GvaAnnouncementsInfo, error)
	Last() (*model.GvaAnnouncementsInfo, error)
	Find() ([]*model.GvaAnnouncementsInfo, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GvaAnnouncementsInfo, err error)
	FindInBatches(result *[]*model.GvaAnnouncementsInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.GvaAnnouncementsInfo) (info gen.ResultInfo, err error)
	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	Updates(value interface{}) (info gen.ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
	UpdateFrom(q gen.SubQuery) gen.Dao
	Attrs(attrs ...field.AssignExpr) IGvaAnnouncementsInfoDo
	Assign(attrs ...field.AssignExpr) IGvaAnnouncementsInfoDo
	Joins(fields ...field.RelationField) IGvaAnnouncementsInfoDo
	Preload(fields ...field.RelationField) IGvaAnnouncementsInfoDo
	FirstOrInit() (*model.GvaAnnouncementsInfo, error)
	FirstOrCreate() (*model.GvaAnnouncementsInfo, error)
	FindByPage(offset int, limit int) (result []*model.GvaAnnouncementsInfo, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Rows() (*sql.Rows, error)
	Row() *sql.Row
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) IGvaAnnouncementsInfoDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (g gvaAnnouncementsInfoDo) Debug() IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Debug())
}

func (g gvaAnnouncementsInfoDo) WithContext(ctx context.Context) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.WithContext(ctx))
}

func (g gvaAnnouncementsInfoDo) ReadDB() IGvaAnnouncementsInfoDo {
	return g.Clauses(dbresolver.Read)
}

func (g gvaAnnouncementsInfoDo) WriteDB() IGvaAnnouncementsInfoDo {
	return g.Clauses(dbresolver.Write)
}

func (g gvaAnnouncementsInfoDo) Session(config *gorm.Session) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Session(config))
}

func (g gvaAnnouncementsInfoDo) Clauses(conds ...clause.Expression) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Clauses(conds...))
}

func (g gvaAnnouncementsInfoDo) Returning(value interface{}, columns ...string) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Returning(value, columns...))
}

func (g gvaAnnouncementsInfoDo) Not(conds ...gen.Condition) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Not(conds...))
}

func (g gvaAnnouncementsInfoDo) Or(conds ...gen.Condition) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Or(conds...))
}

func (g gvaAnnouncementsInfoDo) Select(conds ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Select(conds...))
}

func (g gvaAnnouncementsInfoDo) Where(conds ...gen.Condition) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Where(conds...))
}

func (g gvaAnnouncementsInfoDo) Order(conds ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Order(conds...))
}

func (g gvaAnnouncementsInfoDo) Distinct(cols ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Distinct(cols...))
}

func (g gvaAnnouncementsInfoDo) Omit(cols ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Omit(cols...))
}

func (g gvaAnnouncementsInfoDo) Join(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Join(table, on...))
}

func (g gvaAnnouncementsInfoDo) LeftJoin(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.LeftJoin(table, on...))
}

func (g gvaAnnouncementsInfoDo) RightJoin(table schema.Tabler, on ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.RightJoin(table, on...))
}

func (g gvaAnnouncementsInfoDo) Group(cols ...field.Expr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Group(cols...))
}

func (g gvaAnnouncementsInfoDo) Having(conds ...gen.Condition) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Having(conds...))
}

func (g gvaAnnouncementsInfoDo) Limit(limit int) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Limit(limit))
}

func (g gvaAnnouncementsInfoDo) Offset(offset int) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Offset(offset))
}

func (g gvaAnnouncementsInfoDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Scopes(funcs...))
}

func (g gvaAnnouncementsInfoDo) Unscoped() IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Unscoped())
}

func (g gvaAnnouncementsInfoDo) Create(values ...*model.GvaAnnouncementsInfo) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Create(values)
}

func (g gvaAnnouncementsInfoDo) CreateInBatches(values []*model.GvaAnnouncementsInfo, batchSize int) error {
	return g.DO.CreateInBatches(values, batchSize)
}

// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (g gvaAnnouncementsInfoDo) Save(values ...*model.GvaAnnouncementsInfo) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Save(values)
}

func (g gvaAnnouncementsInfoDo) First() (*model.GvaAnnouncementsInfo, error) {
	if result, err := g.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.GvaAnnouncementsInfo), nil
	}
}

func (g gvaAnnouncementsInfoDo) Take() (*model.GvaAnnouncementsInfo, error) {
	if result, err := g.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.GvaAnnouncementsInfo), nil
	}
}

func (g gvaAnnouncementsInfoDo) Last() (*model.GvaAnnouncementsInfo, error) {
	if result, err := g.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.GvaAnnouncementsInfo), nil
	}
}

func (g gvaAnnouncementsInfoDo) Find() ([]*model.GvaAnnouncementsInfo, error) {
	result, err := g.DO.Find()
	return result.([]*model.GvaAnnouncementsInfo), err
}

func (g gvaAnnouncementsInfoDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GvaAnnouncementsInfo, err error) {
	buf := make([]*model.GvaAnnouncementsInfo, 0, batchSize)
	err = g.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
		defer func() { results = append(results, buf...) }()
		return fc(tx, batch)
	})
	return results, err
}

func (g gvaAnnouncementsInfoDo) FindInBatches(result *[]*model.GvaAnnouncementsInfo, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return g.DO.FindInBatches(result, batchSize, fc)
}

func (g gvaAnnouncementsInfoDo) Attrs(attrs ...field.AssignExpr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Attrs(attrs...))
}

func (g gvaAnnouncementsInfoDo) Assign(attrs ...field.AssignExpr) IGvaAnnouncementsInfoDo {
	return g.withDO(g.DO.Assign(attrs...))
}

func (g gvaAnnouncementsInfoDo) Joins(fields ...field.RelationField) IGvaAnnouncementsInfoDo {
	for _, _f := range fields {
		g = *g.withDO(g.DO.Joins(_f))
	}
	return &g
}

func (g gvaAnnouncementsInfoDo) Preload(fields ...field.RelationField) IGvaAnnouncementsInfoDo {
	for _, _f := range fields {
		g = *g.withDO(g.DO.Preload(_f))
	}
	return &g
}

func (g gvaAnnouncementsInfoDo) FirstOrInit() (*model.GvaAnnouncementsInfo, error) {
	if result, err := g.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.GvaAnnouncementsInfo), nil
	}
}

func (g gvaAnnouncementsInfoDo) FirstOrCreate() (*model.GvaAnnouncementsInfo, error) {
	if result, err := g.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.GvaAnnouncementsInfo), nil
	}
}

func (g gvaAnnouncementsInfoDo) FindByPage(offset int, limit int) (result []*model.GvaAnnouncementsInfo, count int64, err error) {
	result, err = g.Offset(offset).Limit(limit).Find()
	if err != nil {
		return
	}

	if size := len(result); 0 < limit && 0 < size && size < limit {
		count = int64(size + offset)
		return
	}

	count, err = g.Offset(-1).Limit(-1).Count()
	return
}

func (g gvaAnnouncementsInfoDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = g.Count()
	if err != nil {
		return
	}

	err = g.Offset(offset).Limit(limit).Scan(result)
	return
}

func (g gvaAnnouncementsInfoDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

func (g gvaAnnouncementsInfoDo) Delete(models ...*model.GvaAnnouncementsInfo) (result gen.ResultInfo, err error) {
	return g.DO.Delete(models)
}

func (g *gvaAnnouncementsInfoDo) withDO(do gen.Dao) *gvaAnnouncementsInfoDo {
	g.DO = *do.(*gen.DO)
	return g
}
