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

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	systemroles "github.com/openimsdk/openkf/server/internal/models/system_roles"
)

func newSysCustomer(db *gorm.DB, opts ...gen.DOOption) sysCustomer {
	_sysCustomer := sysCustomer{}

	_sysCustomer.sysCustomerDo.UseDB(db, opts...)
	_sysCustomer.sysCustomerDo.UseModel(&systemroles.SysCustomer{})

	tableName := _sysCustomer.sysCustomerDo.TableName()
	_sysCustomer.ALL = field.NewAsterisk(tableName)
	_sysCustomer.Id = field.NewUint(tableName, "id")
	_sysCustomer.CreatedAt = field.NewTime(tableName, "created_at")
	_sysCustomer.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysCustomer.DeletedAt = field.NewTime(tableName, "deleted_at")
	_sysCustomer.UUID = field.NewString(tableName, "uuid")
	_sysCustomer.Email = field.NewString(tableName, "email")
	_sysCustomer.Nickname = field.NewString(tableName, "nickname")
	_sysCustomer.Avatar = field.NewString(tableName, "avatar")
	_sysCustomer.Description = field.NewString(tableName, "description")
	_sysCustomer.IsEnable = field.NewBool(tableName, "is_enable")
	_sysCustomer.Device = field.NewString(tableName, "device")
	_sysCustomer.IPAddress = field.NewString(tableName, "ip_address")
	_sysCustomer.Source = field.NewString(tableName, "source")
	_sysCustomer.SourceType = field.NewInt(tableName, "source_type")

	_sysCustomer.fillFieldMap()

	return _sysCustomer
}

type sysCustomer struct {
	sysCustomerDo sysCustomerDo

	ALL         field.Asterisk
	Id          field.Uint
	CreatedAt   field.Time
	UpdatedAt   field.Time
	DeletedAt   field.Time
	UUID        field.String
	Email       field.String
	Nickname    field.String
	Avatar      field.String
	Description field.String
	IsEnable    field.Bool
	Device      field.String
	IPAddress   field.String
	Source      field.String
	SourceType  field.Int

	fieldMap map[string]field.Expr
}

func (s sysCustomer) Table(newTableName string) *sysCustomer {
	s.sysCustomerDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s sysCustomer) As(alias string) *sysCustomer {
	s.sysCustomerDo.DO = *(s.sysCustomerDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *sysCustomer) updateTableName(table string) *sysCustomer {
	s.ALL = field.NewAsterisk(table)
	s.Id = field.NewUint(table, "id")
	s.CreatedAt = field.NewTime(table, "created_at")
	s.UpdatedAt = field.NewTime(table, "updated_at")
	s.DeletedAt = field.NewTime(table, "deleted_at")
	s.UUID = field.NewString(table, "uuid")
	s.Email = field.NewString(table, "email")
	s.Nickname = field.NewString(table, "nickname")
	s.Avatar = field.NewString(table, "avatar")
	s.Description = field.NewString(table, "description")
	s.IsEnable = field.NewBool(table, "is_enable")
	s.Device = field.NewString(table, "device")
	s.IPAddress = field.NewString(table, "ip_address")
	s.Source = field.NewString(table, "source")
	s.SourceType = field.NewInt(table, "source_type")

	s.fillFieldMap()

	return s
}

func (s *sysCustomer) WithContext(ctx context.Context) ISysCustomerDo {
	return s.sysCustomerDo.WithContext(ctx)
}

func (s sysCustomer) TableName() string { return s.sysCustomerDo.TableName() }

func (s sysCustomer) Alias() string { return s.sysCustomerDo.Alias() }

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

func (s *sysCustomer) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 14)
	s.fieldMap["id"] = s.Id
	s.fieldMap["created_at"] = s.CreatedAt
	s.fieldMap["updated_at"] = s.UpdatedAt
	s.fieldMap["deleted_at"] = s.DeletedAt
	s.fieldMap["uuid"] = s.UUID
	s.fieldMap["email"] = s.Email
	s.fieldMap["nickname"] = s.Nickname
	s.fieldMap["avatar"] = s.Avatar
	s.fieldMap["description"] = s.Description
	s.fieldMap["is_enable"] = s.IsEnable
	s.fieldMap["device"] = s.Device
	s.fieldMap["ip_address"] = s.IPAddress
	s.fieldMap["source"] = s.Source
	s.fieldMap["source_type"] = s.SourceType
}

func (s sysCustomer) clone(db *gorm.DB) sysCustomer {
	s.sysCustomerDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s sysCustomer) replaceDB(db *gorm.DB) sysCustomer {
	s.sysCustomerDo.ReplaceDB(db)
	return s
}

type sysCustomerDo struct{ gen.DO }

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

func (s sysCustomerDo) Debug() ISysCustomerDo {
	return s.withDO(s.DO.Debug())
}

func (s sysCustomerDo) WithContext(ctx context.Context) ISysCustomerDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysCustomerDo) ReadDB() ISysCustomerDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysCustomerDo) WriteDB() ISysCustomerDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysCustomerDo) Session(config *gorm.Session) ISysCustomerDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysCustomerDo) Clauses(conds ...clause.Expression) ISysCustomerDo {
	return s.withDO(s.DO.Clauses(conds...))
}

func (s sysCustomerDo) Returning(value interface{}, columns ...string) ISysCustomerDo {
	return s.withDO(s.DO.Returning(value, columns...))
}

func (s sysCustomerDo) Not(conds ...gen.Condition) ISysCustomerDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysCustomerDo) Or(conds ...gen.Condition) ISysCustomerDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysCustomerDo) Select(conds ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysCustomerDo) Where(conds ...gen.Condition) ISysCustomerDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysCustomerDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysCustomerDo {
	return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (s sysCustomerDo) Order(conds ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysCustomerDo) Distinct(cols ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysCustomerDo) Omit(cols ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Omit(cols...))
}

func (s sysCustomerDo) Join(table schema.Tabler, on ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Join(table, on...))
}

func (s sysCustomerDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.LeftJoin(table, on...))
}

func (s sysCustomerDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.RightJoin(table, on...))
}

func (s sysCustomerDo) Group(cols ...field.Expr) ISysCustomerDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysCustomerDo) Having(conds ...gen.Condition) ISysCustomerDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysCustomerDo) Limit(limit int) ISysCustomerDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysCustomerDo) Offset(offset int) ISysCustomerDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysCustomerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysCustomerDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysCustomerDo) Unscoped() ISysCustomerDo {
	return s.withDO(s.DO.Unscoped())
}

func (s sysCustomerDo) Create(values ...*systemroles.SysCustomer) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

func (s sysCustomerDo) CreateInBatches(values []*systemroles.SysCustomer, batchSize int) error {
	return s.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 (s sysCustomerDo) Save(values ...*systemroles.SysCustomer) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Save(values)
}

func (s sysCustomerDo) First() (*systemroles.SysCustomer, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*systemroles.SysCustomer), nil
	}
}

func (s sysCustomerDo) Take() (*systemroles.SysCustomer, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*systemroles.SysCustomer), nil
	}
}

func (s sysCustomerDo) Last() (*systemroles.SysCustomer, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*systemroles.SysCustomer), nil
	}
}

func (s sysCustomerDo) Find() ([]*systemroles.SysCustomer, error) {
	result, err := s.DO.Find()
	return result.([]*systemroles.SysCustomer), err
}

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

func (s sysCustomerDo) Attrs(attrs ...field.AssignExpr) ISysCustomerDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysCustomerDo) Assign(attrs ...field.AssignExpr) ISysCustomerDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s sysCustomerDo) FirstOrInit() (*systemroles.SysCustomer, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*systemroles.SysCustomer), nil
	}
}

func (s sysCustomerDo) FirstOrCreate() (*systemroles.SysCustomer, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*systemroles.SysCustomer), nil
	}
}

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

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

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

func (s sysCustomerDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s sysCustomerDo) Delete(models ...*systemroles.SysCustomer) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *sysCustomerDo) withDO(do gen.Dao) *sysCustomerDo {
	s.DO = *do.(*gen.DO)
	return s
}
