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

import (
	"app/internal/models"
	"context"

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

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

	"gorm.io/plugin/dbresolver"
)

func newPrepTask(db *gorm.DB, opts ...gen.DOOption) prepTask {
	_prepTask := prepTask{}

	_prepTask.prepTaskDo.UseDB(db, opts...)
	_prepTask.prepTaskDo.UseModel(&models.PrepTask{})

	tableName := _prepTask.prepTaskDo.TableName()
	_prepTask.ALL = field.NewAsterisk(tableName)
	_prepTask.Id = field.NewUint(tableName, "id")
	_prepTask.Status = field.NewString(tableName, "status")
	_prepTask.Description = field.NewString(tableName, "description")
	_prepTask.TaskId = field.NewUint(tableName, "task_id")
	_prepTask.WorkAreaId = field.NewUint(tableName, "work_area_id")
	_prepTask.CreatedAt = field.NewInt64(tableName, "created_at")
	_prepTask.Deadline = field.NewInt64(tableName, "deadline")
	_prepTask.Task = prepTaskBelongsToTask{
		db: db.Session(&gorm.Session{}),

		RelationField: field.NewRelation("Task", "models.Task"),
		ProductType: struct {
			field.RelationField
		}{
			RelationField: field.NewRelation("Task.ProductType", "models.ProductType"),
		},
		Order: struct {
			field.RelationField
			ProductType struct {
				field.RelationField
			}
			Customer struct {
				field.RelationField
				Orders struct {
					field.RelationField
				}
			}
			Tasks struct {
				field.RelationField
			}
		}{
			RelationField: field.NewRelation("Task.Order", "models.Order"),
			ProductType: struct {
				field.RelationField
			}{
				RelationField: field.NewRelation("Task.Order.ProductType", "models.ProductType"),
			},
			Customer: struct {
				field.RelationField
				Orders struct {
					field.RelationField
				}
			}{
				RelationField: field.NewRelation("Task.Order.Customer", "models.Customer"),
				Orders: struct {
					field.RelationField
				}{
					RelationField: field.NewRelation("Task.Order.Customer.Orders", "models.Order"),
				},
			},
			Tasks: struct {
				field.RelationField
			}{
				RelationField: field.NewRelation("Task.Order.Tasks", "models.Task"),
			},
		},
		PrepTasks: struct {
			field.RelationField
			Task struct {
				field.RelationField
			}
			WorkArea struct {
				field.RelationField
				Workshop struct {
					field.RelationField
					WorkAreas struct {
						field.RelationField
					}
					Workers struct {
						field.RelationField
						Workshop struct {
							field.RelationField
						}
						TeamTasks struct {
							field.RelationField
							TeamType struct {
								field.RelationField
							}
							TeamLeader struct {
								field.RelationField
							}
							WorkArea struct {
								field.RelationField
							}
							TeamMembers struct {
								field.RelationField
							}
						}
					}
					Tasks struct {
						field.RelationField
					}
				}
				PrepTasks struct {
					field.RelationField
				}
				Shifts struct {
					field.RelationField
					ProductType struct {
						field.RelationField
					}
					WorkArea struct {
						field.RelationField
					}
				}
				TeamTasks struct {
					field.RelationField
				}
			}
		}{
			RelationField: field.NewRelation("Task.PrepTasks", "models.PrepTask"),
			Task: struct {
				field.RelationField
			}{
				RelationField: field.NewRelation("Task.PrepTasks.Task", "models.Task"),
			},
			WorkArea: struct {
				field.RelationField
				Workshop struct {
					field.RelationField
					WorkAreas struct {
						field.RelationField
					}
					Workers struct {
						field.RelationField
						Workshop struct {
							field.RelationField
						}
						TeamTasks struct {
							field.RelationField
							TeamType struct {
								field.RelationField
							}
							TeamLeader struct {
								field.RelationField
							}
							WorkArea struct {
								field.RelationField
							}
							TeamMembers struct {
								field.RelationField
							}
						}
					}
					Tasks struct {
						field.RelationField
					}
				}
				PrepTasks struct {
					field.RelationField
				}
				Shifts struct {
					field.RelationField
					ProductType struct {
						field.RelationField
					}
					WorkArea struct {
						field.RelationField
					}
				}
				TeamTasks struct {
					field.RelationField
				}
			}{
				RelationField: field.NewRelation("Task.PrepTasks.WorkArea", "models.WorkArea"),
				Workshop: struct {
					field.RelationField
					WorkAreas struct {
						field.RelationField
					}
					Workers struct {
						field.RelationField
						Workshop struct {
							field.RelationField
						}
						TeamTasks struct {
							field.RelationField
							TeamType struct {
								field.RelationField
							}
							TeamLeader struct {
								field.RelationField
							}
							WorkArea struct {
								field.RelationField
							}
							TeamMembers struct {
								field.RelationField
							}
						}
					}
					Tasks struct {
						field.RelationField
					}
				}{
					RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop", "models.Workshop"),
					WorkAreas: struct {
						field.RelationField
					}{
						RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.WorkAreas", "models.WorkArea"),
					},
					Workers: struct {
						field.RelationField
						Workshop struct {
							field.RelationField
						}
						TeamTasks struct {
							field.RelationField
							TeamType struct {
								field.RelationField
							}
							TeamLeader struct {
								field.RelationField
							}
							WorkArea struct {
								field.RelationField
							}
							TeamMembers struct {
								field.RelationField
							}
						}
					}{
						RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers", "models.Worker"),
						Workshop: struct {
							field.RelationField
						}{
							RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.Workshop", "models.Workshop"),
						},
						TeamTasks: struct {
							field.RelationField
							TeamType struct {
								field.RelationField
							}
							TeamLeader struct {
								field.RelationField
							}
							WorkArea struct {
								field.RelationField
							}
							TeamMembers struct {
								field.RelationField
							}
						}{
							RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks", "models.TeamTask"),
							TeamType: struct {
								field.RelationField
							}{
								RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamType", "models.TeamType"),
							},
							TeamLeader: struct {
								field.RelationField
							}{
								RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamLeader", "models.Worker"),
							},
							WorkArea: struct {
								field.RelationField
							}{
								RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.WorkArea", "models.WorkArea"),
							},
							TeamMembers: struct {
								field.RelationField
							}{
								RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Workers.TeamTasks.TeamMembers", "models.Worker"),
							},
						},
					},
					Tasks: struct {
						field.RelationField
					}{
						RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Workshop.Tasks", "models.Task"),
					},
				},
				PrepTasks: struct {
					field.RelationField
				}{
					RelationField: field.NewRelation("Task.PrepTasks.WorkArea.PrepTasks", "models.PrepTask"),
				},
				Shifts: struct {
					field.RelationField
					ProductType struct {
						field.RelationField
					}
					WorkArea struct {
						field.RelationField
					}
				}{
					RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts", "models.Shift"),
					ProductType: struct {
						field.RelationField
					}{
						RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts.ProductType", "models.ProductType"),
					},
					WorkArea: struct {
						field.RelationField
					}{
						RelationField: field.NewRelation("Task.PrepTasks.WorkArea.Shifts.WorkArea", "models.WorkArea"),
					},
				},
				TeamTasks: struct {
					field.RelationField
				}{
					RelationField: field.NewRelation("Task.PrepTasks.WorkArea.TeamTasks", "models.TeamTask"),
				},
			},
		},
		Workshops: struct {
			field.RelationField
		}{
			RelationField: field.NewRelation("Task.Workshops", "models.Workshop"),
		},
	}

	_prepTask.WorkArea = prepTaskBelongsToWorkArea{
		db: db.Session(&gorm.Session{}),

		RelationField: field.NewRelation("WorkArea", "models.WorkArea"),
	}

	_prepTask.fillFieldMap()

	return _prepTask
}

type prepTask struct {
	prepTaskDo

	ALL         field.Asterisk
	Id          field.Uint
	Status      field.String
	Description field.String
	TaskId      field.Uint
	WorkAreaId  field.Uint
	CreatedAt   field.Int64
	Deadline    field.Int64
	Task        prepTaskBelongsToTask

	WorkArea prepTaskBelongsToWorkArea

	fieldMap map[string]field.Expr
}

func (p prepTask) Table(newTableName string) *prepTask {
	p.prepTaskDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

func (p prepTask) As(alias string) *prepTask {
	p.prepTaskDo.DO = *(p.prepTaskDo.As(alias).(*gen.DO))
	return p.updateTableName(alias)
}

func (p *prepTask) updateTableName(table string) *prepTask {
	p.ALL = field.NewAsterisk(table)
	p.Id = field.NewUint(table, "id")
	p.Status = field.NewString(table, "status")
	p.Description = field.NewString(table, "description")
	p.TaskId = field.NewUint(table, "task_id")
	p.WorkAreaId = field.NewUint(table, "work_area_id")
	p.CreatedAt = field.NewInt64(table, "created_at")
	p.Deadline = field.NewInt64(table, "deadline")

	p.fillFieldMap()

	return p
}

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

func (p *prepTask) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 9)
	p.fieldMap["id"] = p.Id
	p.fieldMap["status"] = p.Status
	p.fieldMap["description"] = p.Description
	p.fieldMap["task_id"] = p.TaskId
	p.fieldMap["work_area_id"] = p.WorkAreaId
	p.fieldMap["created_at"] = p.CreatedAt
	p.fieldMap["deadline"] = p.Deadline

}

func (p prepTask) clone(db *gorm.DB) prepTask {
	p.prepTaskDo.ReplaceConnPool(db.Statement.ConnPool)
	return p
}

func (p prepTask) replaceDB(db *gorm.DB) prepTask {
	p.prepTaskDo.ReplaceDB(db)
	return p
}

type prepTaskBelongsToTask struct {
	db *gorm.DB

	field.RelationField

	ProductType struct {
		field.RelationField
	}
	Order struct {
		field.RelationField
		ProductType struct {
			field.RelationField
		}
		Customer struct {
			field.RelationField
			Orders struct {
				field.RelationField
			}
		}
		Tasks struct {
			field.RelationField
		}
	}
	PrepTasks struct {
		field.RelationField
		Task struct {
			field.RelationField
		}
		WorkArea struct {
			field.RelationField
			Workshop struct {
				field.RelationField
				WorkAreas struct {
					field.RelationField
				}
				Workers struct {
					field.RelationField
					Workshop struct {
						field.RelationField
					}
					TeamTasks struct {
						field.RelationField
						TeamType struct {
							field.RelationField
						}
						TeamLeader struct {
							field.RelationField
						}
						WorkArea struct {
							field.RelationField
						}
						TeamMembers struct {
							field.RelationField
						}
					}
				}
				Tasks struct {
					field.RelationField
				}
			}
			PrepTasks struct {
				field.RelationField
			}
			Shifts struct {
				field.RelationField
				ProductType struct {
					field.RelationField
				}
				WorkArea struct {
					field.RelationField
				}
			}
			TeamTasks struct {
				field.RelationField
			}
		}
	}
	Workshops struct {
		field.RelationField
	}
}

func (a prepTaskBelongsToTask) Where(conds ...field.Expr) *prepTaskBelongsToTask {
	if len(conds) == 0 {
		return &a
	}

	exprs := make([]clause.Expression, 0, len(conds))
	for _, cond := range conds {
		exprs = append(exprs, cond.BeCond().(clause.Expression))
	}
	a.db = a.db.Clauses(clause.Where{Exprs: exprs})
	return &a
}

func (a prepTaskBelongsToTask) WithContext(ctx context.Context) *prepTaskBelongsToTask {
	a.db = a.db.WithContext(ctx)
	return &a
}

func (a prepTaskBelongsToTask) Session(session *gorm.Session) *prepTaskBelongsToTask {
	a.db = a.db.Session(session)
	return &a
}

func (a prepTaskBelongsToTask) Model(m *models.PrepTask) *prepTaskBelongsToTaskTx {
	return &prepTaskBelongsToTaskTx{a.db.Model(m).Association(a.Name())}
}

type prepTaskBelongsToTaskTx struct{ tx *gorm.Association }

func (a prepTaskBelongsToTaskTx) Find() (result *models.Task, err error) {
	return result, a.tx.Find(&result)
}

func (a prepTaskBelongsToTaskTx) Append(values ...*models.Task) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Append(targetValues...)
}

func (a prepTaskBelongsToTaskTx) Replace(values ...*models.Task) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Replace(targetValues...)
}

func (a prepTaskBelongsToTaskTx) Delete(values ...*models.Task) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Delete(targetValues...)
}

func (a prepTaskBelongsToTaskTx) Clear() error {
	return a.tx.Clear()
}

func (a prepTaskBelongsToTaskTx) Count() int64 {
	return a.tx.Count()
}

type prepTaskBelongsToWorkArea struct {
	db *gorm.DB

	field.RelationField
}

func (a prepTaskBelongsToWorkArea) Where(conds ...field.Expr) *prepTaskBelongsToWorkArea {
	if len(conds) == 0 {
		return &a
	}

	exprs := make([]clause.Expression, 0, len(conds))
	for _, cond := range conds {
		exprs = append(exprs, cond.BeCond().(clause.Expression))
	}
	a.db = a.db.Clauses(clause.Where{Exprs: exprs})
	return &a
}

func (a prepTaskBelongsToWorkArea) WithContext(ctx context.Context) *prepTaskBelongsToWorkArea {
	a.db = a.db.WithContext(ctx)
	return &a
}

func (a prepTaskBelongsToWorkArea) Session(session *gorm.Session) *prepTaskBelongsToWorkArea {
	a.db = a.db.Session(session)
	return &a
}

func (a prepTaskBelongsToWorkArea) Model(m *models.PrepTask) *prepTaskBelongsToWorkAreaTx {
	return &prepTaskBelongsToWorkAreaTx{a.db.Model(m).Association(a.Name())}
}

type prepTaskBelongsToWorkAreaTx struct{ tx *gorm.Association }

func (a prepTaskBelongsToWorkAreaTx) Find() (result *models.WorkArea, err error) {
	return result, a.tx.Find(&result)
}

func (a prepTaskBelongsToWorkAreaTx) Append(values ...*models.WorkArea) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Append(targetValues...)
}

func (a prepTaskBelongsToWorkAreaTx) Replace(values ...*models.WorkArea) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Replace(targetValues...)
}

func (a prepTaskBelongsToWorkAreaTx) Delete(values ...*models.WorkArea) (err error) {
	targetValues := make([]interface{}, len(values))
	for i, v := range values {
		targetValues[i] = v
	}
	return a.tx.Delete(targetValues...)
}

func (a prepTaskBelongsToWorkAreaTx) Clear() error {
	return a.tx.Clear()
}

func (a prepTaskBelongsToWorkAreaTx) Count() int64 {
	return a.tx.Count()
}

type prepTaskDo struct{ gen.DO }

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

func (p prepTaskDo) Debug() IPrepTaskDo {
	return p.withDO(p.DO.Debug())
}

func (p prepTaskDo) WithContext(ctx context.Context) IPrepTaskDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p prepTaskDo) ReadDB() IPrepTaskDo {
	return p.Clauses(dbresolver.Read)
}

func (p prepTaskDo) WriteDB() IPrepTaskDo {
	return p.Clauses(dbresolver.Write)
}

func (p prepTaskDo) Session(config *gorm.Session) IPrepTaskDo {
	return p.withDO(p.DO.Session(config))
}

func (p prepTaskDo) Clauses(conds ...clause.Expression) IPrepTaskDo {
	return p.withDO(p.DO.Clauses(conds...))
}

func (p prepTaskDo) Returning(value interface{}, columns ...string) IPrepTaskDo {
	return p.withDO(p.DO.Returning(value, columns...))
}

func (p prepTaskDo) Not(conds ...gen.Condition) IPrepTaskDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p prepTaskDo) Or(conds ...gen.Condition) IPrepTaskDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p prepTaskDo) Select(conds ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p prepTaskDo) Where(conds ...gen.Condition) IPrepTaskDo {
	return p.withDO(p.DO.Where(conds...))
}

func (p prepTaskDo) Order(conds ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p prepTaskDo) Distinct(cols ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p prepTaskDo) Omit(cols ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Omit(cols...))
}

func (p prepTaskDo) Join(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Join(table, on...))
}

func (p prepTaskDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.LeftJoin(table, on...))
}

func (p prepTaskDo) RightJoin(table schema.Tabler, on ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.RightJoin(table, on...))
}

func (p prepTaskDo) Group(cols ...field.Expr) IPrepTaskDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p prepTaskDo) Having(conds ...gen.Condition) IPrepTaskDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p prepTaskDo) Limit(limit int) IPrepTaskDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p prepTaskDo) Offset(offset int) IPrepTaskDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p prepTaskDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPrepTaskDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p prepTaskDo) Unscoped() IPrepTaskDo {
	return p.withDO(p.DO.Unscoped())
}

func (p prepTaskDo) Create(values ...*models.PrepTask) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Create(values)
}

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

func (p prepTaskDo) First() (*models.PrepTask, error) {
	if result, err := p.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*models.PrepTask), nil
	}
}

func (p prepTaskDo) Take() (*models.PrepTask, error) {
	if result, err := p.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*models.PrepTask), nil
	}
}

func (p prepTaskDo) Last() (*models.PrepTask, error) {
	if result, err := p.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*models.PrepTask), nil
	}
}

func (p prepTaskDo) Find() ([]*models.PrepTask, error) {
	result, err := p.DO.Find()
	return result.([]*models.PrepTask), err
}

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

func (p prepTaskDo) Attrs(attrs ...field.AssignExpr) IPrepTaskDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p prepTaskDo) Assign(attrs ...field.AssignExpr) IPrepTaskDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

func (p prepTaskDo) FirstOrInit() (*models.PrepTask, error) {
	if result, err := p.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*models.PrepTask), nil
	}
}

func (p prepTaskDo) FirstOrCreate() (*models.PrepTask, error) {
	if result, err := p.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*models.PrepTask), nil
	}
}

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

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

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

func (p prepTaskDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

func (p prepTaskDo) Delete(models ...*models.PrepTask) (result gen.ResultInfo, err error) {
	return p.DO.Delete(models)
}

func (p *prepTaskDo) withDO(do gen.Dao) *prepTaskDo {
	p.DO = *do.(*gen.DO)
	return p
}
