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

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"

	"fafa-crawler/src/models"
)

func newLibraryProduct(db *gorm.DB, opts ...gen.DOOption) libraryProduct {
	_libraryProduct := libraryProduct{}

	_libraryProduct.libraryProductDo.UseDB(db, opts...)
	_libraryProduct.libraryProductDo.UseModel(&models.LibraryProduct{})

	tableName := _libraryProduct.libraryProductDo.TableName()
	_libraryProduct.ALL = field.NewAsterisk(tableName)
	_libraryProduct.ID = field.NewUint64(tableName, "id")
	_libraryProduct.Sname = field.NewString(tableName, "sname")
	_libraryProduct.Name = field.NewString(tableName, "name")
	_libraryProduct.Title = field.NewString(tableName, "title")
	_libraryProduct.Barcode = field.NewString(tableName, "barcode")
	_libraryProduct.Category1St = field.NewString(tableName, "category_1st")
	_libraryProduct.Category2Nd = field.NewString(tableName, "category_2nd")
	_libraryProduct.Category = field.NewString(tableName, "category")
	_libraryProduct.Price = field.NewFloat64(tableName, "price")
	_libraryProduct.Keywords = field.NewString(tableName, "keywords")
	_libraryProduct.Thumb = field.NewString(tableName, "thumb")
	_libraryProduct.Brand = field.NewString(tableName, "brand")
	_libraryProduct.Spec = field.NewString(tableName, "spec")
	_libraryProduct.MadeIn = field.NewString(tableName, "made_in")
	_libraryProduct.Weight = field.NewString(tableName, "weight")
	_libraryProduct.WeightUnit = field.NewString(tableName, "weight_unit")
	_libraryProduct.SellingPoint = field.NewString(tableName, "selling_point")
	_libraryProduct.Intro = field.NewString(tableName, "intro")
	_libraryProduct.Seq = field.NewInt32(tableName, "seq")
	_libraryProduct.Source = field.NewString(tableName, "source")
	_libraryProduct.Status = field.NewInt32(tableName, "status")
	_libraryProduct.CreatedAt = field.NewTime(tableName, "created_at")
	_libraryProduct.UpdatedAt = field.NewTime(tableName, "updated_at")

	_libraryProduct.fillFieldMap()

	return _libraryProduct
}

// libraryProduct 商品库商品表
type libraryProduct struct {
	libraryProductDo

	ALL          field.Asterisk
	ID           field.Uint64  // 商品ID
	Sname        field.String  // 商品简称，作为匹配关键字
	Name         field.String  // 商品名
	Title        field.String  // 商品标题
	Barcode      field.String  // 条形码/Barcode
	Category1St  field.String  // 第一级分类
	Category2Nd  field.String  // 第二级分类
	Category     field.String  // 第3级分类
	Price        field.Float64 // 商品原价
	Keywords     field.String  // 商品关键字
	Thumb        field.String  // 封面图主图
	Brand        field.String  // 品牌
	Spec         field.String  // 商品规格，多个使用英文分号分割
	MadeIn       field.String  // 产地
	Weight       field.String  // 重量值
	WeightUnit   field.String  // 重量单位
	SellingPoint field.String  // 商品卖点
	Intro        field.String  // 商品介绍
	Seq          field.Int32   // 排序值，越小越前面
	Source       field.String  // 来源ID
	Status       field.Int32   // 状态 1-有效 2-无效
	CreatedAt    field.Time    // 创建时间
	UpdatedAt    field.Time    // 更新时间

	fieldMap map[string]field.Expr
}

func (l libraryProduct) Table(newTableName string) *libraryProduct {
	l.libraryProductDo.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

func (l libraryProduct) As(alias string) *libraryProduct {
	l.libraryProductDo.DO = *(l.libraryProductDo.As(alias).(*gen.DO))
	return l.updateTableName(alias)
}

func (l *libraryProduct) updateTableName(table string) *libraryProduct {
	l.ALL = field.NewAsterisk(table)
	l.ID = field.NewUint64(table, "id")
	l.Sname = field.NewString(table, "sname")
	l.Name = field.NewString(table, "name")
	l.Title = field.NewString(table, "title")
	l.Barcode = field.NewString(table, "barcode")
	l.Category1St = field.NewString(table, "category_1st")
	l.Category2Nd = field.NewString(table, "category_2nd")
	l.Category = field.NewString(table, "category")
	l.Price = field.NewFloat64(table, "price")
	l.Keywords = field.NewString(table, "keywords")
	l.Thumb = field.NewString(table, "thumb")
	l.Brand = field.NewString(table, "brand")
	l.Spec = field.NewString(table, "spec")
	l.MadeIn = field.NewString(table, "made_in")
	l.Weight = field.NewString(table, "weight")
	l.WeightUnit = field.NewString(table, "weight_unit")
	l.SellingPoint = field.NewString(table, "selling_point")
	l.Intro = field.NewString(table, "intro")
	l.Seq = field.NewInt32(table, "seq")
	l.Source = field.NewString(table, "source")
	l.Status = field.NewInt32(table, "status")
	l.CreatedAt = field.NewTime(table, "created_at")
	l.UpdatedAt = field.NewTime(table, "updated_at")

	l.fillFieldMap()

	return l
}

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

func (l *libraryProduct) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 23)
	l.fieldMap["id"] = l.ID
	l.fieldMap["sname"] = l.Sname
	l.fieldMap["name"] = l.Name
	l.fieldMap["title"] = l.Title
	l.fieldMap["barcode"] = l.Barcode
	l.fieldMap["category_1st"] = l.Category1St
	l.fieldMap["category_2nd"] = l.Category2Nd
	l.fieldMap["category"] = l.Category
	l.fieldMap["price"] = l.Price
	l.fieldMap["keywords"] = l.Keywords
	l.fieldMap["thumb"] = l.Thumb
	l.fieldMap["brand"] = l.Brand
	l.fieldMap["spec"] = l.Spec
	l.fieldMap["made_in"] = l.MadeIn
	l.fieldMap["weight"] = l.Weight
	l.fieldMap["weight_unit"] = l.WeightUnit
	l.fieldMap["selling_point"] = l.SellingPoint
	l.fieldMap["intro"] = l.Intro
	l.fieldMap["seq"] = l.Seq
	l.fieldMap["source"] = l.Source
	l.fieldMap["status"] = l.Status
	l.fieldMap["created_at"] = l.CreatedAt
	l.fieldMap["updated_at"] = l.UpdatedAt
}

func (l libraryProduct) clone(db *gorm.DB) libraryProduct {
	l.libraryProductDo.ReplaceConnPool(db.Statement.ConnPool)
	return l
}

func (l libraryProduct) replaceDB(db *gorm.DB) libraryProduct {
	l.libraryProductDo.ReplaceDB(db)
	return l
}

type libraryProductDo struct{ gen.DO }

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

func (l libraryProductDo) Debug() ILibraryProductDo {
	return l.withDO(l.DO.Debug())
}

func (l libraryProductDo) WithContext(ctx context.Context) ILibraryProductDo {
	return l.withDO(l.DO.WithContext(ctx))
}

func (l libraryProductDo) ReadDB() ILibraryProductDo {
	return l.Clauses(dbresolver.Read)
}

func (l libraryProductDo) WriteDB() ILibraryProductDo {
	return l.Clauses(dbresolver.Write)
}

func (l libraryProductDo) Session(config *gorm.Session) ILibraryProductDo {
	return l.withDO(l.DO.Session(config))
}

func (l libraryProductDo) Clauses(conds ...clause.Expression) ILibraryProductDo {
	return l.withDO(l.DO.Clauses(conds...))
}

func (l libraryProductDo) Returning(value interface{}, columns ...string) ILibraryProductDo {
	return l.withDO(l.DO.Returning(value, columns...))
}

func (l libraryProductDo) Not(conds ...gen.Condition) ILibraryProductDo {
	return l.withDO(l.DO.Not(conds...))
}

func (l libraryProductDo) Or(conds ...gen.Condition) ILibraryProductDo {
	return l.withDO(l.DO.Or(conds...))
}

func (l libraryProductDo) Select(conds ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Select(conds...))
}

func (l libraryProductDo) Where(conds ...gen.Condition) ILibraryProductDo {
	return l.withDO(l.DO.Where(conds...))
}

func (l libraryProductDo) Order(conds ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Order(conds...))
}

func (l libraryProductDo) Distinct(cols ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Distinct(cols...))
}

func (l libraryProductDo) Omit(cols ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Omit(cols...))
}

func (l libraryProductDo) Join(table schema.Tabler, on ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Join(table, on...))
}

func (l libraryProductDo) LeftJoin(table schema.Tabler, on ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.LeftJoin(table, on...))
}

func (l libraryProductDo) RightJoin(table schema.Tabler, on ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.RightJoin(table, on...))
}

func (l libraryProductDo) Group(cols ...field.Expr) ILibraryProductDo {
	return l.withDO(l.DO.Group(cols...))
}

func (l libraryProductDo) Having(conds ...gen.Condition) ILibraryProductDo {
	return l.withDO(l.DO.Having(conds...))
}

func (l libraryProductDo) Limit(limit int) ILibraryProductDo {
	return l.withDO(l.DO.Limit(limit))
}

func (l libraryProductDo) Offset(offset int) ILibraryProductDo {
	return l.withDO(l.DO.Offset(offset))
}

func (l libraryProductDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ILibraryProductDo {
	return l.withDO(l.DO.Scopes(funcs...))
}

func (l libraryProductDo) Unscoped() ILibraryProductDo {
	return l.withDO(l.DO.Unscoped())
}

func (l libraryProductDo) Create(values ...*models.LibraryProduct) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Create(values)
}

func (l libraryProductDo) CreateInBatches(values []*models.LibraryProduct, batchSize int) error {
	return l.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 (l libraryProductDo) Save(values ...*models.LibraryProduct) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Save(values)
}

func (l libraryProductDo) First() (*models.LibraryProduct, error) {
	if result, err := l.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*models.LibraryProduct), nil
	}
}

func (l libraryProductDo) Take() (*models.LibraryProduct, error) {
	if result, err := l.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*models.LibraryProduct), nil
	}
}

func (l libraryProductDo) Last() (*models.LibraryProduct, error) {
	if result, err := l.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*models.LibraryProduct), nil
	}
}

func (l libraryProductDo) Find() ([]*models.LibraryProduct, error) {
	result, err := l.DO.Find()
	return result.([]*models.LibraryProduct), err
}

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

func (l libraryProductDo) Attrs(attrs ...field.AssignExpr) ILibraryProductDo {
	return l.withDO(l.DO.Attrs(attrs...))
}

func (l libraryProductDo) Assign(attrs ...field.AssignExpr) ILibraryProductDo {
	return l.withDO(l.DO.Assign(attrs...))
}

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

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

func (l libraryProductDo) FirstOrInit() (*models.LibraryProduct, error) {
	if result, err := l.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*models.LibraryProduct), nil
	}
}

func (l libraryProductDo) FirstOrCreate() (*models.LibraryProduct, error) {
	if result, err := l.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*models.LibraryProduct), nil
	}
}

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

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

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

func (l libraryProductDo) Scan(result interface{}) (err error) {
	return l.DO.Scan(result)
}

func (l libraryProductDo) Delete(models ...*models.LibraryProduct) (result gen.ResultInfo, err error) {
	return l.DO.Delete(models)
}

func (l *libraryProductDo) withDO(do gen.Dao) *libraryProductDo {
	l.DO = *do.(*gen.DO)
	return l
}
