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

	"git.kocoder.xyz/kocoded/vt/model"
)

func newKalender(db *gorm.DB, opts ...gen.DOOption) kalender {
	_kalender := kalender{}

	_kalender.kalenderDo.UseDB(db, opts...)
	_kalender.kalenderDo.UseModel(&model.Kalender{})

	tableName := _kalender.kalenderDo.TableName()
	_kalender.ALL = field.NewAsterisk(tableName)
	_kalender.ID = field.NewUint(tableName, "id")
	_kalender.CreatedAt = field.NewTime(tableName, "created_at")
	_kalender.UpdatedAt = field.NewTime(tableName, "updated_at")
	_kalender.DeletedAt = field.NewField(tableName, "deleted_at")

	_kalender.fillFieldMap()

	return _kalender
}

type kalender struct {
	kalenderDo

	ALL       field.Asterisk
	ID        field.Uint
	CreatedAt field.Time
	UpdatedAt field.Time
	DeletedAt field.Field

	fieldMap map[string]field.Expr
}

func (k kalender) Table(newTableName string) *kalender {
	k.kalenderDo.UseTable(newTableName)
	return k.updateTableName(newTableName)
}

func (k kalender) As(alias string) *kalender {
	k.kalenderDo.DO = *(k.kalenderDo.As(alias).(*gen.DO))
	return k.updateTableName(alias)
}

func (k *kalender) updateTableName(table string) *kalender {
	k.ALL = field.NewAsterisk(table)
	k.ID = field.NewUint(table, "id")
	k.CreatedAt = field.NewTime(table, "created_at")
	k.UpdatedAt = field.NewTime(table, "updated_at")
	k.DeletedAt = field.NewField(table, "deleted_at")

	k.fillFieldMap()

	return k
}

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

func (k *kalender) fillFieldMap() {
	k.fieldMap = make(map[string]field.Expr, 4)
	k.fieldMap["id"] = k.ID
	k.fieldMap["created_at"] = k.CreatedAt
	k.fieldMap["updated_at"] = k.UpdatedAt
	k.fieldMap["deleted_at"] = k.DeletedAt
}

func (k kalender) clone(db *gorm.DB) kalender {
	k.kalenderDo.ReplaceConnPool(db.Statement.ConnPool)
	return k
}

func (k kalender) replaceDB(db *gorm.DB) kalender {
	k.kalenderDo.ReplaceDB(db)
	return k
}

type kalenderDo struct{ gen.DO }

type IKalenderDo interface {
	gen.SubQuery
	Debug() IKalenderDo
	WithContext(ctx context.Context) IKalenderDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() IKalenderDo
	WriteDB() IKalenderDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) IKalenderDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) IKalenderDo
	Not(conds ...gen.Condition) IKalenderDo
	Or(conds ...gen.Condition) IKalenderDo
	Select(conds ...field.Expr) IKalenderDo
	Where(conds ...gen.Condition) IKalenderDo
	Order(conds ...field.Expr) IKalenderDo
	Distinct(cols ...field.Expr) IKalenderDo
	Omit(cols ...field.Expr) IKalenderDo
	Join(table schema.Tabler, on ...field.Expr) IKalenderDo
	LeftJoin(table schema.Tabler, on ...field.Expr) IKalenderDo
	RightJoin(table schema.Tabler, on ...field.Expr) IKalenderDo
	Group(cols ...field.Expr) IKalenderDo
	Having(conds ...gen.Condition) IKalenderDo
	Limit(limit int) IKalenderDo
	Offset(offset int) IKalenderDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) IKalenderDo
	Unscoped() IKalenderDo
	Create(values ...*model.Kalender) error
	CreateInBatches(values []*model.Kalender, batchSize int) error
	Save(values ...*model.Kalender) error
	First() (*model.Kalender, error)
	Take() (*model.Kalender, error)
	Last() (*model.Kalender, error)
	Find() ([]*model.Kalender, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Kalender, err error)
	FindInBatches(result *[]*model.Kalender, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.Kalender) (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) IKalenderDo
	Assign(attrs ...field.AssignExpr) IKalenderDo
	Joins(fields ...field.RelationField) IKalenderDo
	Preload(fields ...field.RelationField) IKalenderDo
	FirstOrInit() (*model.Kalender, error)
	FirstOrCreate() (*model.Kalender, error)
	FindByPage(offset int, limit int) (result []*model.Kalender, 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) IKalenderDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (k kalenderDo) Debug() IKalenderDo {
	return k.withDO(k.DO.Debug())
}

func (k kalenderDo) WithContext(ctx context.Context) IKalenderDo {
	return k.withDO(k.DO.WithContext(ctx))
}

func (k kalenderDo) ReadDB() IKalenderDo {
	return k.Clauses(dbresolver.Read)
}

func (k kalenderDo) WriteDB() IKalenderDo {
	return k.Clauses(dbresolver.Write)
}

func (k kalenderDo) Session(config *gorm.Session) IKalenderDo {
	return k.withDO(k.DO.Session(config))
}

func (k kalenderDo) Clauses(conds ...clause.Expression) IKalenderDo {
	return k.withDO(k.DO.Clauses(conds...))
}

func (k kalenderDo) Returning(value interface{}, columns ...string) IKalenderDo {
	return k.withDO(k.DO.Returning(value, columns...))
}

func (k kalenderDo) Not(conds ...gen.Condition) IKalenderDo {
	return k.withDO(k.DO.Not(conds...))
}

func (k kalenderDo) Or(conds ...gen.Condition) IKalenderDo {
	return k.withDO(k.DO.Or(conds...))
}

func (k kalenderDo) Select(conds ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Select(conds...))
}

func (k kalenderDo) Where(conds ...gen.Condition) IKalenderDo {
	return k.withDO(k.DO.Where(conds...))
}

func (k kalenderDo) Order(conds ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Order(conds...))
}

func (k kalenderDo) Distinct(cols ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Distinct(cols...))
}

func (k kalenderDo) Omit(cols ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Omit(cols...))
}

func (k kalenderDo) Join(table schema.Tabler, on ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Join(table, on...))
}

func (k kalenderDo) LeftJoin(table schema.Tabler, on ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.LeftJoin(table, on...))
}

func (k kalenderDo) RightJoin(table schema.Tabler, on ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.RightJoin(table, on...))
}

func (k kalenderDo) Group(cols ...field.Expr) IKalenderDo {
	return k.withDO(k.DO.Group(cols...))
}

func (k kalenderDo) Having(conds ...gen.Condition) IKalenderDo {
	return k.withDO(k.DO.Having(conds...))
}

func (k kalenderDo) Limit(limit int) IKalenderDo {
	return k.withDO(k.DO.Limit(limit))
}

func (k kalenderDo) Offset(offset int) IKalenderDo {
	return k.withDO(k.DO.Offset(offset))
}

func (k kalenderDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IKalenderDo {
	return k.withDO(k.DO.Scopes(funcs...))
}

func (k kalenderDo) Unscoped() IKalenderDo {
	return k.withDO(k.DO.Unscoped())
}

func (k kalenderDo) Create(values ...*model.Kalender) error {
	if len(values) == 0 {
		return nil
	}
	return k.DO.Create(values)
}

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

func (k kalenderDo) First() (*model.Kalender, error) {
	if result, err := k.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Kalender), nil
	}
}

func (k kalenderDo) Take() (*model.Kalender, error) {
	if result, err := k.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Kalender), nil
	}
}

func (k kalenderDo) Last() (*model.Kalender, error) {
	if result, err := k.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Kalender), nil
	}
}

func (k kalenderDo) Find() ([]*model.Kalender, error) {
	result, err := k.DO.Find()
	return result.([]*model.Kalender), err
}

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

func (k kalenderDo) Attrs(attrs ...field.AssignExpr) IKalenderDo {
	return k.withDO(k.DO.Attrs(attrs...))
}

func (k kalenderDo) Assign(attrs ...field.AssignExpr) IKalenderDo {
	return k.withDO(k.DO.Assign(attrs...))
}

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

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

func (k kalenderDo) FirstOrInit() (*model.Kalender, error) {
	if result, err := k.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Kalender), nil
	}
}

func (k kalenderDo) FirstOrCreate() (*model.Kalender, error) {
	if result, err := k.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Kalender), nil
	}
}

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

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

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

func (k kalenderDo) Scan(result interface{}) (err error) {
	return k.DO.Scan(result)
}

func (k kalenderDo) Delete(models ...*model.Kalender) (result gen.ResultInfo, err error) {
	return k.DO.Delete(models)
}

func (k *kalenderDo) withDO(do gen.Dao) *kalenderDo {
	k.DO = *do.(*gen.DO)
	return k
}
