package impl

import (
	"ai_scheduler/internal/data/model"
	"ai_scheduler/utils"

	"gorm.io/gorm"
)

type IssueImpl struct {
	IssueType       BaseRepository[model.AiIssueType]
	IssueAssignRule BaseRepository[model.AiIssueAssignRule]
	IssueAssignUser BaseRepository[model.AiIssueAssignUser]
}

func NewIssueImpl(db *utils.Db) *IssueImpl {
	return &IssueImpl{
		IssueType:       NewBaseModel[model.AiIssueType](db.Client),
		IssueAssignRule: NewBaseModel[model.AiIssueAssignRule](db.Client),
		IssueAssignUser: NewBaseModel[model.AiIssueAssignUser](db.Client),
	}
}

// WithName 名称查询
func (a *IssueImpl) WithName(name string) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("name = ?", name)
	}
}

// WithCode 编码查询
func (a *IssueImpl) WithCode(code string) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("code = ?", code)
	}
}

// WithSysID 系统ID查询
func (a *IssueImpl) WithSysID(sysID any) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("sys_id = ?", sysID)
	}
}

// WithIssueTypeID 问题类型ID查询
func (a *IssueImpl) WithIssueTypeID(issueTypeID any) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("issue_type_id = ?", issueTypeID)
	}
}

// WithRuleID 规则ID查询
func (a *IssueImpl) WithRuleID(ruleID any) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("rule_id = ?", ruleID)
	}
}

// WithStatus 状态查询
func (a *IssueImpl) WithStatus(status any) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("status = ?", status)
	}
}
