// 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 newExaCustomer(db *gorm.DB, opts ...gen.DOOption) exaCustomer {
	_exaCustomer := exaCustomer{}

	_exaCustomer.exaCustomerDo.UseDB(db, opts...)
	_exaCustomer.exaCustomerDo.UseModel(&model.ExaCustomer{})

	tableName := _exaCustomer.exaCustomerDo.TableName()
	_exaCustomer.ALL = field.NewAsterisk(tableName)
	_exaCustomer.ID = field.NewInt64(tableName, "id")
	_exaCustomer.CreatedAt = field.NewTime(tableName, "created_at")
	_exaCustomer.UpdatedAt = field.NewTime(tableName, "updated_at")
	_exaCustomer.DeletedAt = field.NewField(tableName, "deleted_at")
	_exaCustomer.CustomerName = field.NewString(tableName, "customer_name")
	_exaCustomer.CustomerPhoneData = field.NewString(tableName, "customer_phone_data")
	_exaCustomer.SysUserID = field.NewInt64(tableName, "sys_user_id")
	_exaCustomer.SysUserAuthorityID = field.NewInt64(tableName, "sys_user_authority_id")

	_exaCustomer.fillFieldMap()

	return _exaCustomer
}

type exaCustomer struct {
	exaCustomerDo exaCustomerDo

	ALL                field.Asterisk
	ID                 field.Int64
	CreatedAt          field.Time
	UpdatedAt          field.Time
	DeletedAt          field.Field
	CustomerName       field.String // 客户名
	CustomerPhoneData  field.String // 客户手机号
	SysUserID          field.Int64  // 管理ID
	SysUserAuthorityID field.Int64  // 管理角色ID

	fieldMap map[string]field.Expr
}

func (e exaCustomer) Table(newTableName string) *exaCustomer {
	e.exaCustomerDo.UseTable(newTableName)
	return e.updateTableName(newTableName)
}

func (e exaCustomer) As(alias string) *exaCustomer {
	e.exaCustomerDo.DO = *(e.exaCustomerDo.As(alias).(*gen.DO))
	return e.updateTableName(alias)
}

func (e *exaCustomer) updateTableName(table string) *exaCustomer {
	e.ALL = field.NewAsterisk(table)
	e.ID = field.NewInt64(table, "id")
	e.CreatedAt = field.NewTime(table, "created_at")
	e.UpdatedAt = field.NewTime(table, "updated_at")
	e.DeletedAt = field.NewField(table, "deleted_at")
	e.CustomerName = field.NewString(table, "customer_name")
	e.CustomerPhoneData = field.NewString(table, "customer_phone_data")
	e.SysUserID = field.NewInt64(table, "sys_user_id")
	e.SysUserAuthorityID = field.NewInt64(table, "sys_user_authority_id")

	e.fillFieldMap()

	return e
}

func (e *exaCustomer) WithContext(ctx context.Context) IExaCustomerDo {
	return e.exaCustomerDo.WithContext(ctx)
}

func (e exaCustomer) TableName() string { return e.exaCustomerDo.TableName() }

func (e exaCustomer) Alias() string { return e.exaCustomerDo.Alias() }

func (e exaCustomer) Columns(cols ...field.Expr) gen.Columns { return e.exaCustomerDo.Columns(cols...) }

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

func (e *exaCustomer) fillFieldMap() {
	e.fieldMap = make(map[string]field.Expr, 8)
	e.fieldMap["id"] = e.ID
	e.fieldMap["created_at"] = e.CreatedAt
	e.fieldMap["updated_at"] = e.UpdatedAt
	e.fieldMap["deleted_at"] = e.DeletedAt
	e.fieldMap["customer_name"] = e.CustomerName
	e.fieldMap["customer_phone_data"] = e.CustomerPhoneData
	e.fieldMap["sys_user_id"] = e.SysUserID
	e.fieldMap["sys_user_authority_id"] = e.SysUserAuthorityID
}

func (e exaCustomer) clone(db *gorm.DB) exaCustomer {
	e.exaCustomerDo.ReplaceConnPool(db.Statement.ConnPool)
	return e
}

func (e exaCustomer) replaceDB(db *gorm.DB) exaCustomer {
	e.exaCustomerDo.ReplaceDB(db)
	return e
}

type exaCustomerDo struct{ gen.DO }

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

func (e exaCustomerDo) Debug() IExaCustomerDo {
	return e.withDO(e.DO.Debug())
}

func (e exaCustomerDo) WithContext(ctx context.Context) IExaCustomerDo {
	return e.withDO(e.DO.WithContext(ctx))
}

func (e exaCustomerDo) ReadDB() IExaCustomerDo {
	return e.Clauses(dbresolver.Read)
}

func (e exaCustomerDo) WriteDB() IExaCustomerDo {
	return e.Clauses(dbresolver.Write)
}

func (e exaCustomerDo) Session(config *gorm.Session) IExaCustomerDo {
	return e.withDO(e.DO.Session(config))
}

func (e exaCustomerDo) Clauses(conds ...clause.Expression) IExaCustomerDo {
	return e.withDO(e.DO.Clauses(conds...))
}

func (e exaCustomerDo) Returning(value interface{}, columns ...string) IExaCustomerDo {
	return e.withDO(e.DO.Returning(value, columns...))
}

func (e exaCustomerDo) Not(conds ...gen.Condition) IExaCustomerDo {
	return e.withDO(e.DO.Not(conds...))
}

func (e exaCustomerDo) Or(conds ...gen.Condition) IExaCustomerDo {
	return e.withDO(e.DO.Or(conds...))
}

func (e exaCustomerDo) Select(conds ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Select(conds...))
}

func (e exaCustomerDo) Where(conds ...gen.Condition) IExaCustomerDo {
	return e.withDO(e.DO.Where(conds...))
}

func (e exaCustomerDo) Order(conds ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Order(conds...))
}

func (e exaCustomerDo) Distinct(cols ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Distinct(cols...))
}

func (e exaCustomerDo) Omit(cols ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Omit(cols...))
}

func (e exaCustomerDo) Join(table schema.Tabler, on ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Join(table, on...))
}

func (e exaCustomerDo) LeftJoin(table schema.Tabler, on ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.LeftJoin(table, on...))
}

func (e exaCustomerDo) RightJoin(table schema.Tabler, on ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.RightJoin(table, on...))
}

func (e exaCustomerDo) Group(cols ...field.Expr) IExaCustomerDo {
	return e.withDO(e.DO.Group(cols...))
}

func (e exaCustomerDo) Having(conds ...gen.Condition) IExaCustomerDo {
	return e.withDO(e.DO.Having(conds...))
}

func (e exaCustomerDo) Limit(limit int) IExaCustomerDo {
	return e.withDO(e.DO.Limit(limit))
}

func (e exaCustomerDo) Offset(offset int) IExaCustomerDo {
	return e.withDO(e.DO.Offset(offset))
}

func (e exaCustomerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IExaCustomerDo {
	return e.withDO(e.DO.Scopes(funcs...))
}

func (e exaCustomerDo) Unscoped() IExaCustomerDo {
	return e.withDO(e.DO.Unscoped())
}

func (e exaCustomerDo) Create(values ...*model.ExaCustomer) error {
	if len(values) == 0 {
		return nil
	}
	return e.DO.Create(values)
}

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

func (e exaCustomerDo) First() (*model.ExaCustomer, error) {
	if result, err := e.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExaCustomer), nil
	}
}

func (e exaCustomerDo) Take() (*model.ExaCustomer, error) {
	if result, err := e.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExaCustomer), nil
	}
}

func (e exaCustomerDo) Last() (*model.ExaCustomer, error) {
	if result, err := e.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExaCustomer), nil
	}
}

func (e exaCustomerDo) Find() ([]*model.ExaCustomer, error) {
	result, err := e.DO.Find()
	return result.([]*model.ExaCustomer), err
}

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

func (e exaCustomerDo) Attrs(attrs ...field.AssignExpr) IExaCustomerDo {
	return e.withDO(e.DO.Attrs(attrs...))
}

func (e exaCustomerDo) Assign(attrs ...field.AssignExpr) IExaCustomerDo {
	return e.withDO(e.DO.Assign(attrs...))
}

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

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

func (e exaCustomerDo) FirstOrInit() (*model.ExaCustomer, error) {
	if result, err := e.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExaCustomer), nil
	}
}

func (e exaCustomerDo) FirstOrCreate() (*model.ExaCustomer, error) {
	if result, err := e.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExaCustomer), nil
	}
}

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

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

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

func (e exaCustomerDo) Scan(result interface{}) (err error) {
	return e.DO.Scan(result)
}

func (e exaCustomerDo) Delete(models ...*model.ExaCustomer) (result gen.ResultInfo, err error) {
	return e.DO.Delete(models)
}

func (e *exaCustomerDo) withDO(do gen.Dao) *exaCustomerDo {
	e.DO = *do.(*gen.DO)
	return e
}
