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

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	"github.com/flowline-io/flowbot/internal/store/model"
)

func newFileupload(db *gorm.DB, opts ...gen.DOOption) fileupload {
	_fileupload := fileupload{}

	_fileupload.fileuploadDo.UseDB(db, opts...)
	_fileupload.fileuploadDo.UseModel(&model.Fileupload{})

	tableName := _fileupload.fileuploadDo.TableName()
	_fileupload.ALL = field.NewAsterisk(tableName)
	_fileupload.ID = field.NewInt64(tableName, "id")
	_fileupload.UID = field.NewString(tableName, "uid")
	_fileupload.Name = field.NewString(tableName, "name")
	_fileupload.Mimetype = field.NewString(tableName, "mimetype")
	_fileupload.Size = field.NewInt64(tableName, "size")
	_fileupload.Location = field.NewString(tableName, "location")
	_fileupload.State = field.NewField(tableName, "state")
	_fileupload.CreatedAt = field.NewTime(tableName, "created_at")
	_fileupload.UpdatedAt = field.NewTime(tableName, "updated_at")

	_fileupload.fillFieldMap()

	return _fileupload
}

type fileupload struct {
	fileuploadDo

	ALL       field.Asterisk
	ID        field.Int64
	UID       field.String
	Name      field.String
	Mimetype  field.String
	Size      field.Int64
	Location  field.String
	State     field.Field
	CreatedAt field.Time
	UpdatedAt field.Time

	fieldMap map[string]field.Expr
}

func (f fileupload) Table(newTableName string) *fileupload {
	f.fileuploadDo.UseTable(newTableName)
	return f.updateTableName(newTableName)
}

func (f fileupload) As(alias string) *fileupload {
	f.fileuploadDo.DO = *(f.fileuploadDo.As(alias).(*gen.DO))
	return f.updateTableName(alias)
}

func (f *fileupload) updateTableName(table string) *fileupload {
	f.ALL = field.NewAsterisk(table)
	f.ID = field.NewInt64(table, "id")
	f.UID = field.NewString(table, "uid")
	f.Name = field.NewString(table, "name")
	f.Mimetype = field.NewString(table, "mimetype")
	f.Size = field.NewInt64(table, "size")
	f.Location = field.NewString(table, "location")
	f.State = field.NewField(table, "state")
	f.CreatedAt = field.NewTime(table, "created_at")
	f.UpdatedAt = field.NewTime(table, "updated_at")

	f.fillFieldMap()

	return f
}

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

func (f *fileupload) fillFieldMap() {
	f.fieldMap = make(map[string]field.Expr, 9)
	f.fieldMap["id"] = f.ID
	f.fieldMap["uid"] = f.UID
	f.fieldMap["name"] = f.Name
	f.fieldMap["mimetype"] = f.Mimetype
	f.fieldMap["size"] = f.Size
	f.fieldMap["location"] = f.Location
	f.fieldMap["state"] = f.State
	f.fieldMap["created_at"] = f.CreatedAt
	f.fieldMap["updated_at"] = f.UpdatedAt
}

func (f fileupload) clone(db *gorm.DB) fileupload {
	f.fileuploadDo.ReplaceConnPool(db.Statement.ConnPool)
	return f
}

func (f fileupload) replaceDB(db *gorm.DB) fileupload {
	f.fileuploadDo.ReplaceDB(db)
	return f
}

type fileuploadDo struct{ gen.DO }

func (f fileuploadDo) Debug() *fileuploadDo {
	return f.withDO(f.DO.Debug())
}

func (f fileuploadDo) WithContext(ctx context.Context) *fileuploadDo {
	return f.withDO(f.DO.WithContext(ctx))
}

func (f fileuploadDo) ReadDB() *fileuploadDo {
	return f.Clauses(dbresolver.Read)
}

func (f fileuploadDo) WriteDB() *fileuploadDo {
	return f.Clauses(dbresolver.Write)
}

func (f fileuploadDo) Session(config *gorm.Session) *fileuploadDo {
	return f.withDO(f.DO.Session(config))
}

func (f fileuploadDo) Clauses(conds ...clause.Expression) *fileuploadDo {
	return f.withDO(f.DO.Clauses(conds...))
}

func (f fileuploadDo) Returning(value interface{}, columns ...string) *fileuploadDo {
	return f.withDO(f.DO.Returning(value, columns...))
}

func (f fileuploadDo) Not(conds ...gen.Condition) *fileuploadDo {
	return f.withDO(f.DO.Not(conds...))
}

func (f fileuploadDo) Or(conds ...gen.Condition) *fileuploadDo {
	return f.withDO(f.DO.Or(conds...))
}

func (f fileuploadDo) Select(conds ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Select(conds...))
}

func (f fileuploadDo) Where(conds ...gen.Condition) *fileuploadDo {
	return f.withDO(f.DO.Where(conds...))
}

func (f fileuploadDo) Order(conds ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Order(conds...))
}

func (f fileuploadDo) Distinct(cols ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Distinct(cols...))
}

func (f fileuploadDo) Omit(cols ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Omit(cols...))
}

func (f fileuploadDo) Join(table schema.Tabler, on ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Join(table, on...))
}

func (f fileuploadDo) LeftJoin(table schema.Tabler, on ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.LeftJoin(table, on...))
}

func (f fileuploadDo) RightJoin(table schema.Tabler, on ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.RightJoin(table, on...))
}

func (f fileuploadDo) Group(cols ...field.Expr) *fileuploadDo {
	return f.withDO(f.DO.Group(cols...))
}

func (f fileuploadDo) Having(conds ...gen.Condition) *fileuploadDo {
	return f.withDO(f.DO.Having(conds...))
}

func (f fileuploadDo) Limit(limit int) *fileuploadDo {
	return f.withDO(f.DO.Limit(limit))
}

func (f fileuploadDo) Offset(offset int) *fileuploadDo {
	return f.withDO(f.DO.Offset(offset))
}

func (f fileuploadDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *fileuploadDo {
	return f.withDO(f.DO.Scopes(funcs...))
}

func (f fileuploadDo) Unscoped() *fileuploadDo {
	return f.withDO(f.DO.Unscoped())
}

func (f fileuploadDo) Create(values ...*model.Fileupload) error {
	if len(values) == 0 {
		return nil
	}
	return f.DO.Create(values)
}

func (f fileuploadDo) CreateInBatches(values []*model.Fileupload, batchSize int) error {
	return f.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 (f fileuploadDo) Save(values ...*model.Fileupload) error {
	if len(values) == 0 {
		return nil
	}
	return f.DO.Save(values)
}

func (f fileuploadDo) First() (*model.Fileupload, error) {
	if result, err := f.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Fileupload), nil
	}
}

func (f fileuploadDo) Take() (*model.Fileupload, error) {
	if result, err := f.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Fileupload), nil
	}
}

func (f fileuploadDo) Last() (*model.Fileupload, error) {
	if result, err := f.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Fileupload), nil
	}
}

func (f fileuploadDo) Find() ([]*model.Fileupload, error) {
	result, err := f.DO.Find()
	return result.([]*model.Fileupload), err
}

func (f fileuploadDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Fileupload, err error) {
	buf := make([]*model.Fileupload, 0, batchSize)
	err = f.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 (f fileuploadDo) FindInBatches(result *[]*model.Fileupload, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return f.DO.FindInBatches(result, batchSize, fc)
}

func (f fileuploadDo) Attrs(attrs ...field.AssignExpr) *fileuploadDo {
	return f.withDO(f.DO.Attrs(attrs...))
}

func (f fileuploadDo) Assign(attrs ...field.AssignExpr) *fileuploadDo {
	return f.withDO(f.DO.Assign(attrs...))
}

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

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

func (f fileuploadDo) FirstOrInit() (*model.Fileupload, error) {
	if result, err := f.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Fileupload), nil
	}
}

func (f fileuploadDo) FirstOrCreate() (*model.Fileupload, error) {
	if result, err := f.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Fileupload), nil
	}
}

func (f fileuploadDo) FindByPage(offset int, limit int) (result []*model.Fileupload, count int64, err error) {
	result, err = f.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 = f.Offset(-1).Limit(-1).Count()
	return
}

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

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

func (f fileuploadDo) Scan(result interface{}) (err error) {
	return f.DO.Scan(result)
}

func (f fileuploadDo) Delete(models ...*model.Fileupload) (result gen.ResultInfo, err error) {
	return f.DO.Delete(models)
}

func (f *fileuploadDo) withDO(do gen.Dao) *fileuploadDo {
	f.DO = *do.(*gen.DO)
	return f
}
