package data

import (
	"eta/eta_api/models"
)

// CommonClassifyStrategy 通用分类策略接口
type CommonClassifyStrategy interface {
	GetCommonClassifyCols() models.CommonClassifyCols
	GetCommonClassifyById(classifyId int) (*models.CommonClassify, error)
	GetClassifyByParentIdAndName(parentId int, name string, excludeId int) (*models.CommonClassify, error)
	GetClassifySortMaxByParentId(parentId int) (int, error)
	GetFirstClassifyByParentId(parentId int) (*models.CommonClassify, error)

	SetClassifySortByParentId(parentId, classifyId, sort int, sortUpdate string) error
	UpdateCommonClassify(classify *models.CommonClassify, updateCols []string) error
	UpdateClassifyChildByParentId(classifyIds []int, rootId int, stepLevel int) error

	GetCommonClassifyObjCols() models.CommonClassifyObjCols
	GetObjectById(objectId int) (*models.CommonClassifyObj, error)
	GetObjectSortMaxByClassifyId(classifyId int) (int, error)
	GetFirstObjectByClassifyId(classifyId int) (*models.CommonClassifyObj, error)

	SetObjectSortByClassifyId(classifyId, sort, prevObjectId int, sortUpdate string) error
	UpdateCommonClassifyObj(object *models.CommonClassifyObj, updateCols []string) (err error)
}

// CommonClassifyCtx 通用分类上下文
type CommonClassifyCtx struct {
	strategy CommonClassifyStrategy
}

// NewCommonClassifyCtx New一个通用分类上下文
func NewCommonClassifyCtx(strategy CommonClassifyStrategy) *CommonClassifyCtx {
	return &CommonClassifyCtx{strategy: strategy}
}

// GetCommonClassifyCols 通用分类字段映射
func (c *CommonClassifyCtx) GetCommonClassifyCols() models.CommonClassifyCols {
	return c.strategy.GetCommonClassifyCols()
}

// GetCommonClassifyById 通过策略获取分类信息
func (c *CommonClassifyCtx) GetCommonClassifyById(classifyId int) (*models.CommonClassify, error) {
	return c.strategy.GetCommonClassifyById(classifyId)
}

// GetClassifyByParentIdAndName 通过策略获取分类信息
func (c *CommonClassifyCtx) GetClassifyByParentIdAndName(parentId int, name string, excludeId int) (*models.CommonClassify, error) {
	return c.strategy.GetClassifyByParentIdAndName(parentId, name, excludeId)
}

// GetClassifySortMaxByParentId 获取父级分类下最大排序
func (c *CommonClassifyCtx) GetClassifySortMaxByParentId(parentId int) (int, error) {
	return c.strategy.GetClassifySortMaxByParentId(parentId)
}

// GetFirstClassifyByParentId 获取父级分类下首个分类
func (c *CommonClassifyCtx) GetFirstClassifyByParentId(parentId int) (*models.CommonClassify, error) {
	return c.strategy.GetFirstClassifyByParentId(parentId)
}

// SetClassifySortByParentId 通过父级ID更新分类排序
func (c *CommonClassifyCtx) SetClassifySortByParentId(parentId, classifyId, sort int, sortUpdate string) error {
	return c.strategy.SetClassifySortByParentId(parentId, classifyId, sort, sortUpdate)
}

// UpdateCommonClassify 更新通用分类
func (c *CommonClassifyCtx) UpdateCommonClassify(classify *models.CommonClassify, updateCols []string) error {
	return c.strategy.UpdateCommonClassify(classify, updateCols)
}

// UpdateClassifyChildByParentId 更新分类子节点RootId
func (c *CommonClassifyCtx) UpdateClassifyChildByParentId(classifyIds []int, rootId int, stepLevel int) error {
	return c.strategy.UpdateClassifyChildByParentId(classifyIds, rootId, stepLevel)
}

// GetCommonClassifyObjCols 通用分类对象字段映射
func (c *CommonClassifyCtx) GetCommonClassifyObjCols() models.CommonClassifyObjCols {
	return c.strategy.GetCommonClassifyObjCols()
}

// GetObjectById 获取分类对象
func (c *CommonClassifyCtx) GetObjectById(objectId int) (*models.CommonClassifyObj, error) {
	return c.strategy.GetObjectById(objectId)
}

// GetObjectSortMaxByClassifyId 获取分类下最大排序
func (c *CommonClassifyCtx) GetObjectSortMaxByClassifyId(classifyId int) (int, error) {
	return c.strategy.GetObjectSortMaxByClassifyId(classifyId)
}

// GetFirstObjectByClassifyId 获取分类下首个对象
func (c *CommonClassifyCtx) GetFirstObjectByClassifyId(classifyId int) (*models.CommonClassifyObj, error) {
	return c.strategy.GetFirstObjectByClassifyId(classifyId)
}

// SetObjectSortByClassifyId 通过分类ID更新对象排序
func (c *CommonClassifyCtx) SetObjectSortByClassifyId(classifyId, sort, prevObjectId int, sortUpdate string) error {
	return c.strategy.SetObjectSortByClassifyId(classifyId, sort, prevObjectId, sortUpdate)
}

// UpdateCommonClassifyObj 更新分类对象
func (c *CommonClassifyCtx) UpdateCommonClassifyObj(object *models.CommonClassifyObj, updateCols []string) (err error) {
	return c.strategy.UpdateCommonClassifyObj(object, updateCols)
}