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

	customerroles "github.com/openimsdk/openkf/server/internal/models/customer_roles"
)

func newCustomerSlack(db *gorm.DB, opts ...gen.DOOption) customerSlack {
	_customerSlack := customerSlack{}

	_customerSlack.customerSlackDo.UseDB(db, opts...)
	_customerSlack.customerSlackDo.UseModel(&customerroles.CustomerSlack{})

	tableName := _customerSlack.customerSlackDo.TableName()
	_customerSlack.ALL = field.NewAsterisk(tableName)
	_customerSlack.Id = field.NewUint(tableName, "id")
	_customerSlack.CreatedAt = field.NewTime(tableName, "created_at")
	_customerSlack.UpdatedAt = field.NewTime(tableName, "updated_at")
	_customerSlack.DeletedAt = field.NewTime(tableName, "deleted_at")
	_customerSlack.UUID = field.NewString(tableName, "uuid")
	_customerSlack.Email = field.NewString(tableName, "email")
	_customerSlack.Nickname = field.NewString(tableName, "nickname")
	_customerSlack.Avatar = field.NewString(tableName, "avatar")
	_customerSlack.Description = field.NewString(tableName, "description")
	_customerSlack.IsEnable = field.NewBool(tableName, "is_enable")
	_customerSlack.FirstName = field.NewString(tableName, "first_name")
	_customerSlack.LastName = field.NewString(tableName, "last_name")
	_customerSlack.RealName = field.NewString(tableName, "real_name")
	_customerSlack.RealNameNormalized = field.NewString(tableName, "real_name_normalized")
	_customerSlack.DisplayName = field.NewString(tableName, "display_name")
	_customerSlack.DisplayNameNormalized = field.NewString(tableName, "display_name_normalized")
	_customerSlack.Skype = field.NewString(tableName, "skype")
	_customerSlack.Phone = field.NewString(tableName, "phone")
	_customerSlack.Image24 = field.NewString(tableName, "image24")
	_customerSlack.Image32 = field.NewString(tableName, "image32")
	_customerSlack.Image48 = field.NewString(tableName, "image48")
	_customerSlack.Image72 = field.NewString(tableName, "image72")
	_customerSlack.Image192 = field.NewString(tableName, "image192")
	_customerSlack.Image512 = field.NewString(tableName, "image512")
	_customerSlack.ImageOriginal = field.NewString(tableName, "image_original")
	_customerSlack.Title = field.NewString(tableName, "title")
	_customerSlack.BotID = field.NewString(tableName, "bot_id")
	_customerSlack.ApiAppID = field.NewString(tableName, "api_app_id")
	_customerSlack.StatusText = field.NewString(tableName, "status_text")
	_customerSlack.StatusEmoji = field.NewString(tableName, "status_emoji")
	_customerSlack.StatusExpiration = field.NewInt(tableName, "status_expiration")
	_customerSlack.Team = field.NewString(tableName, "team")

	_customerSlack.fillFieldMap()

	return _customerSlack
}

type customerSlack struct {
	customerSlackDo customerSlackDo

	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
	FirstName             field.String
	LastName              field.String
	RealName              field.String
	RealNameNormalized    field.String
	DisplayName           field.String
	DisplayNameNormalized field.String
	Skype                 field.String
	Phone                 field.String
	Image24               field.String
	Image32               field.String
	Image48               field.String
	Image72               field.String
	Image192              field.String
	Image512              field.String
	ImageOriginal         field.String
	Title                 field.String
	BotID                 field.String
	ApiAppID              field.String
	StatusText            field.String
	StatusEmoji           field.String
	StatusExpiration      field.Int
	Team                  field.String

	fieldMap map[string]field.Expr
}

func (c customerSlack) Table(newTableName string) *customerSlack {
	c.customerSlackDo.UseTable(newTableName)
	return c.updateTableName(newTableName)
}

func (c customerSlack) As(alias string) *customerSlack {
	c.customerSlackDo.DO = *(c.customerSlackDo.As(alias).(*gen.DO))
	return c.updateTableName(alias)
}

func (c *customerSlack) updateTableName(table string) *customerSlack {
	c.ALL = field.NewAsterisk(table)
	c.Id = field.NewUint(table, "id")
	c.CreatedAt = field.NewTime(table, "created_at")
	c.UpdatedAt = field.NewTime(table, "updated_at")
	c.DeletedAt = field.NewTime(table, "deleted_at")
	c.UUID = field.NewString(table, "uuid")
	c.Email = field.NewString(table, "email")
	c.Nickname = field.NewString(table, "nickname")
	c.Avatar = field.NewString(table, "avatar")
	c.Description = field.NewString(table, "description")
	c.IsEnable = field.NewBool(table, "is_enable")
	c.FirstName = field.NewString(table, "first_name")
	c.LastName = field.NewString(table, "last_name")
	c.RealName = field.NewString(table, "real_name")
	c.RealNameNormalized = field.NewString(table, "real_name_normalized")
	c.DisplayName = field.NewString(table, "display_name")
	c.DisplayNameNormalized = field.NewString(table, "display_name_normalized")
	c.Skype = field.NewString(table, "skype")
	c.Phone = field.NewString(table, "phone")
	c.Image24 = field.NewString(table, "image24")
	c.Image32 = field.NewString(table, "image32")
	c.Image48 = field.NewString(table, "image48")
	c.Image72 = field.NewString(table, "image72")
	c.Image192 = field.NewString(table, "image192")
	c.Image512 = field.NewString(table, "image512")
	c.ImageOriginal = field.NewString(table, "image_original")
	c.Title = field.NewString(table, "title")
	c.BotID = field.NewString(table, "bot_id")
	c.ApiAppID = field.NewString(table, "api_app_id")
	c.StatusText = field.NewString(table, "status_text")
	c.StatusEmoji = field.NewString(table, "status_emoji")
	c.StatusExpiration = field.NewInt(table, "status_expiration")
	c.Team = field.NewString(table, "team")

	c.fillFieldMap()

	return c
}

func (c *customerSlack) WithContext(ctx context.Context) ICustomerSlackDo {
	return c.customerSlackDo.WithContext(ctx)
}

func (c customerSlack) TableName() string { return c.customerSlackDo.TableName() }

func (c customerSlack) Alias() string { return c.customerSlackDo.Alias() }

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

func (c *customerSlack) fillFieldMap() {
	c.fieldMap = make(map[string]field.Expr, 32)
	c.fieldMap["id"] = c.Id
	c.fieldMap["created_at"] = c.CreatedAt
	c.fieldMap["updated_at"] = c.UpdatedAt
	c.fieldMap["deleted_at"] = c.DeletedAt
	c.fieldMap["uuid"] = c.UUID
	c.fieldMap["email"] = c.Email
	c.fieldMap["nickname"] = c.Nickname
	c.fieldMap["avatar"] = c.Avatar
	c.fieldMap["description"] = c.Description
	c.fieldMap["is_enable"] = c.IsEnable
	c.fieldMap["first_name"] = c.FirstName
	c.fieldMap["last_name"] = c.LastName
	c.fieldMap["real_name"] = c.RealName
	c.fieldMap["real_name_normalized"] = c.RealNameNormalized
	c.fieldMap["display_name"] = c.DisplayName
	c.fieldMap["display_name_normalized"] = c.DisplayNameNormalized
	c.fieldMap["skype"] = c.Skype
	c.fieldMap["phone"] = c.Phone
	c.fieldMap["image24"] = c.Image24
	c.fieldMap["image32"] = c.Image32
	c.fieldMap["image48"] = c.Image48
	c.fieldMap["image72"] = c.Image72
	c.fieldMap["image192"] = c.Image192
	c.fieldMap["image512"] = c.Image512
	c.fieldMap["image_original"] = c.ImageOriginal
	c.fieldMap["title"] = c.Title
	c.fieldMap["bot_id"] = c.BotID
	c.fieldMap["api_app_id"] = c.ApiAppID
	c.fieldMap["status_text"] = c.StatusText
	c.fieldMap["status_emoji"] = c.StatusEmoji
	c.fieldMap["status_expiration"] = c.StatusExpiration
	c.fieldMap["team"] = c.Team
}

func (c customerSlack) clone(db *gorm.DB) customerSlack {
	c.customerSlackDo.ReplaceConnPool(db.Statement.ConnPool)
	return c
}

func (c customerSlack) replaceDB(db *gorm.DB) customerSlack {
	c.customerSlackDo.ReplaceDB(db)
	return c
}

type customerSlackDo struct{ gen.DO }

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

func (c customerSlackDo) Debug() ICustomerSlackDo {
	return c.withDO(c.DO.Debug())
}

func (c customerSlackDo) WithContext(ctx context.Context) ICustomerSlackDo {
	return c.withDO(c.DO.WithContext(ctx))
}

func (c customerSlackDo) ReadDB() ICustomerSlackDo {
	return c.Clauses(dbresolver.Read)
}

func (c customerSlackDo) WriteDB() ICustomerSlackDo {
	return c.Clauses(dbresolver.Write)
}

func (c customerSlackDo) Session(config *gorm.Session) ICustomerSlackDo {
	return c.withDO(c.DO.Session(config))
}

func (c customerSlackDo) Clauses(conds ...clause.Expression) ICustomerSlackDo {
	return c.withDO(c.DO.Clauses(conds...))
}

func (c customerSlackDo) Returning(value interface{}, columns ...string) ICustomerSlackDo {
	return c.withDO(c.DO.Returning(value, columns...))
}

func (c customerSlackDo) Not(conds ...gen.Condition) ICustomerSlackDo {
	return c.withDO(c.DO.Not(conds...))
}

func (c customerSlackDo) Or(conds ...gen.Condition) ICustomerSlackDo {
	return c.withDO(c.DO.Or(conds...))
}

func (c customerSlackDo) Select(conds ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Select(conds...))
}

func (c customerSlackDo) Where(conds ...gen.Condition) ICustomerSlackDo {
	return c.withDO(c.DO.Where(conds...))
}

func (c customerSlackDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ICustomerSlackDo {
	return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (c customerSlackDo) Order(conds ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Order(conds...))
}

func (c customerSlackDo) Distinct(cols ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Distinct(cols...))
}

func (c customerSlackDo) Omit(cols ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Omit(cols...))
}

func (c customerSlackDo) Join(table schema.Tabler, on ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Join(table, on...))
}

func (c customerSlackDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.LeftJoin(table, on...))
}

func (c customerSlackDo) RightJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.RightJoin(table, on...))
}

func (c customerSlackDo) Group(cols ...field.Expr) ICustomerSlackDo {
	return c.withDO(c.DO.Group(cols...))
}

func (c customerSlackDo) Having(conds ...gen.Condition) ICustomerSlackDo {
	return c.withDO(c.DO.Having(conds...))
}

func (c customerSlackDo) Limit(limit int) ICustomerSlackDo {
	return c.withDO(c.DO.Limit(limit))
}

func (c customerSlackDo) Offset(offset int) ICustomerSlackDo {
	return c.withDO(c.DO.Offset(offset))
}

func (c customerSlackDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICustomerSlackDo {
	return c.withDO(c.DO.Scopes(funcs...))
}

func (c customerSlackDo) Unscoped() ICustomerSlackDo {
	return c.withDO(c.DO.Unscoped())
}

func (c customerSlackDo) Create(values ...*customerroles.CustomerSlack) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Create(values)
}

func (c customerSlackDo) CreateInBatches(values []*customerroles.CustomerSlack, batchSize int) error {
	return c.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 (c customerSlackDo) Save(values ...*customerroles.CustomerSlack) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Save(values)
}

func (c customerSlackDo) First() (*customerroles.CustomerSlack, error) {
	if result, err := c.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*customerroles.CustomerSlack), nil
	}
}

func (c customerSlackDo) Take() (*customerroles.CustomerSlack, error) {
	if result, err := c.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*customerroles.CustomerSlack), nil
	}
}

func (c customerSlackDo) Last() (*customerroles.CustomerSlack, error) {
	if result, err := c.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*customerroles.CustomerSlack), nil
	}
}

func (c customerSlackDo) Find() ([]*customerroles.CustomerSlack, error) {
	result, err := c.DO.Find()
	return result.([]*customerroles.CustomerSlack), err
}

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

func (c customerSlackDo) Attrs(attrs ...field.AssignExpr) ICustomerSlackDo {
	return c.withDO(c.DO.Attrs(attrs...))
}

func (c customerSlackDo) Assign(attrs ...field.AssignExpr) ICustomerSlackDo {
	return c.withDO(c.DO.Assign(attrs...))
}

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

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

func (c customerSlackDo) FirstOrInit() (*customerroles.CustomerSlack, error) {
	if result, err := c.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*customerroles.CustomerSlack), nil
	}
}

func (c customerSlackDo) FirstOrCreate() (*customerroles.CustomerSlack, error) {
	if result, err := c.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*customerroles.CustomerSlack), nil
	}
}

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

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

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

func (c customerSlackDo) Scan(result interface{}) (err error) {
	return c.DO.Scan(result)
}

func (c customerSlackDo) Delete(models ...*customerroles.CustomerSlack) (result gen.ResultInfo, err error) {
	return c.DO.Delete(models)
}

func (c *customerSlackDo) withDO(do gen.Dao) *customerSlackDo {
	c.DO = *do.(*gen.DO)
	return c
}
