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

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

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

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newChatReportLog(db *gorm.DB, opts ...gen.DOOption) chatReportLog {
	_chatReportLog := chatReportLog{}

	_chatReportLog.chatReportLogDo.UseDB(db, opts...)
	_chatReportLog.chatReportLogDo.UseModel(&model.ChatReportLog{})

	tableName := _chatReportLog.chatReportLogDo.TableName()
	_chatReportLog.ALL = field.NewAsterisk(tableName)
	_chatReportLog.ID = field.NewInt64(tableName, "id")
	_chatReportLog.PlayerID = field.NewInt64(tableName, "player_id")
	_chatReportLog.PlayerName = field.NewString(tableName, "player_name")
	_chatReportLog.ServerID = field.NewInt32(tableName, "server_id")
	_chatReportLog.ClanChatID = field.NewString(tableName, "clan_chat_id")
	_chatReportLog.ClanPlayerID = field.NewInt64(tableName, "clan_player_id")
	_chatReportLog.ClanPlayerName = field.NewString(tableName, "clan_player_name")
	_chatReportLog.ClanServerID = field.NewInt32(tableName, "clan_server_id")
	_chatReportLog.ClanContent = field.NewString(tableName, "clan_content")
	_chatReportLog.ClanChatChannel = field.NewInt32(tableName, "clan_chat_channel")
	_chatReportLog.LeagueCode = field.NewString(tableName, "league_code")
	_chatReportLog.ClanTime = field.NewInt64(tableName, "clan_time")
	_chatReportLog.CreateTime = field.NewInt64(tableName, "create_time")

	_chatReportLog.fillFieldMap()

	return _chatReportLog
}

type chatReportLog struct {
	chatReportLogDo chatReportLogDo

	ALL             field.Asterisk
	ID              field.Int64
	PlayerID        field.Int64  // 举报者id
	PlayerName      field.String // 举报者昵称
	ServerID        field.Int32  // 举报者服务器id
	ClanChatID      field.String // 违规的消息id
	ClanPlayerID    field.Int64  // 违规者id
	ClanPlayerName  field.String // 违规者昵称
	ClanServerID    field.Int32  // 违规者服务器id
	ClanContent     field.String // 违规消息内容
	ClanChatChannel field.Int32  // 频道类型
	LeagueCode      field.String // 联盟code
	ClanTime        field.Int64  // 违规时间(毫秒)
	CreateTime      field.Int64  // 上传时间(毫秒)

	fieldMap map[string]field.Expr
}

func (c chatReportLog) Table(newTableName string) *chatReportLog {
	c.chatReportLogDo.UseTable(newTableName)
	return c.updateTableName(newTableName)
}

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

func (c *chatReportLog) updateTableName(table string) *chatReportLog {
	c.ALL = field.NewAsterisk(table)
	c.ID = field.NewInt64(table, "id")
	c.PlayerID = field.NewInt64(table, "player_id")
	c.PlayerName = field.NewString(table, "player_name")
	c.ServerID = field.NewInt32(table, "server_id")
	c.ClanChatID = field.NewString(table, "clan_chat_id")
	c.ClanPlayerID = field.NewInt64(table, "clan_player_id")
	c.ClanPlayerName = field.NewString(table, "clan_player_name")
	c.ClanServerID = field.NewInt32(table, "clan_server_id")
	c.ClanContent = field.NewString(table, "clan_content")
	c.ClanChatChannel = field.NewInt32(table, "clan_chat_channel")
	c.LeagueCode = field.NewString(table, "league_code")
	c.ClanTime = field.NewInt64(table, "clan_time")
	c.CreateTime = field.NewInt64(table, "create_time")

	c.fillFieldMap()

	return c
}

func (c *chatReportLog) WithContext(ctx context.Context) *chatReportLogDo {
	return c.chatReportLogDo.WithContext(ctx)
}

func (c chatReportLog) TableName() string { return c.chatReportLogDo.TableName() }

func (c chatReportLog) Alias() string { return c.chatReportLogDo.Alias() }

func (c chatReportLog) Columns(cols ...field.Expr) gen.Columns {
	return c.chatReportLogDo.Columns(cols...)
}

func (c *chatReportLog) 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 *chatReportLog) fillFieldMap() {
	c.fieldMap = make(map[string]field.Expr, 13)
	c.fieldMap["id"] = c.ID
	c.fieldMap["player_id"] = c.PlayerID
	c.fieldMap["player_name"] = c.PlayerName
	c.fieldMap["server_id"] = c.ServerID
	c.fieldMap["clan_chat_id"] = c.ClanChatID
	c.fieldMap["clan_player_id"] = c.ClanPlayerID
	c.fieldMap["clan_player_name"] = c.ClanPlayerName
	c.fieldMap["clan_server_id"] = c.ClanServerID
	c.fieldMap["clan_content"] = c.ClanContent
	c.fieldMap["clan_chat_channel"] = c.ClanChatChannel
	c.fieldMap["league_code"] = c.LeagueCode
	c.fieldMap["clan_time"] = c.ClanTime
	c.fieldMap["create_time"] = c.CreateTime
}

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

func (c chatReportLog) replaceDB(db *gorm.DB) chatReportLog {
	c.chatReportLogDo.ReplaceDB(db)
	return c
}

type chatReportLogDo struct{ gen.DO }

func (c chatReportLogDo) Debug() *chatReportLogDo {
	return c.withDO(c.DO.Debug())
}

func (c chatReportLogDo) WithContext(ctx context.Context) *chatReportLogDo {
	return c.withDO(c.DO.WithContext(ctx))
}

func (c chatReportLogDo) ReadDB() *chatReportLogDo {
	return c.Clauses(dbresolver.Read)
}

func (c chatReportLogDo) WriteDB() *chatReportLogDo {
	return c.Clauses(dbresolver.Write)
}

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

func (c chatReportLogDo) Clauses(conds ...clause.Expression) *chatReportLogDo {
	return c.withDO(c.DO.Clauses(conds...))
}

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

func (c chatReportLogDo) Not(conds ...gen.Condition) *chatReportLogDo {
	return c.withDO(c.DO.Not(conds...))
}

func (c chatReportLogDo) Or(conds ...gen.Condition) *chatReportLogDo {
	return c.withDO(c.DO.Or(conds...))
}

func (c chatReportLogDo) Select(conds ...field.Expr) *chatReportLogDo {
	return c.withDO(c.DO.Select(conds...))
}

func (c chatReportLogDo) Where(conds ...gen.Condition) *chatReportLogDo {
	return c.withDO(c.DO.Where(conds...))
}

func (c chatReportLogDo) Order(conds ...field.Expr) *chatReportLogDo {
	return c.withDO(c.DO.Order(conds...))
}

func (c chatReportLogDo) Distinct(cols ...field.Expr) *chatReportLogDo {
	return c.withDO(c.DO.Distinct(cols...))
}

func (c chatReportLogDo) Omit(cols ...field.Expr) *chatReportLogDo {
	return c.withDO(c.DO.Omit(cols...))
}

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

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

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

func (c chatReportLogDo) Group(cols ...field.Expr) *chatReportLogDo {
	return c.withDO(c.DO.Group(cols...))
}

func (c chatReportLogDo) Having(conds ...gen.Condition) *chatReportLogDo {
	return c.withDO(c.DO.Having(conds...))
}

func (c chatReportLogDo) Limit(limit int) *chatReportLogDo {
	return c.withDO(c.DO.Limit(limit))
}

func (c chatReportLogDo) Offset(offset int) *chatReportLogDo {
	return c.withDO(c.DO.Offset(offset))
}

func (c chatReportLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *chatReportLogDo {
	return c.withDO(c.DO.Scopes(funcs...))
}

func (c chatReportLogDo) Unscoped() *chatReportLogDo {
	return c.withDO(c.DO.Unscoped())
}

func (c chatReportLogDo) Create(values ...*model.ChatReportLog) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Create(values)
}

func (c chatReportLogDo) CreateInBatches(values []*model.ChatReportLog, 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 chatReportLogDo) Save(values ...*model.ChatReportLog) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Save(values)
}

func (c chatReportLogDo) First() (*model.ChatReportLog, error) {
	if result, err := c.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChatReportLog), nil
	}
}

func (c chatReportLogDo) Take() (*model.ChatReportLog, error) {
	if result, err := c.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChatReportLog), nil
	}
}

func (c chatReportLogDo) Last() (*model.ChatReportLog, error) {
	if result, err := c.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChatReportLog), nil
	}
}

func (c chatReportLogDo) Find() ([]*model.ChatReportLog, error) {
	result, err := c.DO.Find()
	return result.([]*model.ChatReportLog), err
}

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

func (c chatReportLogDo) Attrs(attrs ...field.AssignExpr) *chatReportLogDo {
	return c.withDO(c.DO.Attrs(attrs...))
}

func (c chatReportLogDo) Assign(attrs ...field.AssignExpr) *chatReportLogDo {
	return c.withDO(c.DO.Assign(attrs...))
}

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

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

func (c chatReportLogDo) FirstOrInit() (*model.ChatReportLog, error) {
	if result, err := c.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChatReportLog), nil
	}
}

func (c chatReportLogDo) FirstOrCreate() (*model.ChatReportLog, error) {
	if result, err := c.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChatReportLog), nil
	}
}

func (c chatReportLogDo) FindByPage(offset int, limit int) (result []*model.ChatReportLog, 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 chatReportLogDo) 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 chatReportLogDo) Scan(result interface{}) (err error) {
	return c.DO.Scan(result)
}

func (c chatReportLogDo) Delete(models ...*model.ChatReportLog) (result gen.ResultInfo, err error) {
	return c.DO.Delete(models)
}

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