package impl

import (
	"ai_scheduler/internal/data/model"
	"ai_scheduler/tmpl/dataTemp"
	"ai_scheduler/utils"
	"time"

	"gorm.io/gorm"
)

type SessionImpl struct {
	dataTemp.DataTemp
	BaseRepository[model.AiSession]
}

func NewSessionImpl(db *utils.Db) *SessionImpl {
	return &SessionImpl{
		DataTemp:       *dataTemp.NewDataTemp(db, new(model.AiSession)),
		BaseRepository: NewBaseModel[model.AiSession](db.Client),
	}
}

// WithUserId 条件：用户ID
func (impl *SessionImpl) WithUserId(userId interface{}) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("user_id = ?", userId)
	}
}

// WithStartTime 条件：会话开始时间
func (impl *SessionImpl) WithStartTime(startTime time.Time) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("create_at >= ?", startTime)
	}
}

// WithSysId 系统id
func (s *SessionImpl) WithSysId(sysId interface{}) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("sys_id = ?", sysId)
	}
}

func (impl *SessionImpl) WithSessionId(sessionId interface{}) CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("session_id = ?", sessionId)
	}
}

// WithDeletedAt 条件：是否删除
func (impl *SessionImpl) WithDeleteAt() CondFunc {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("delete_at IS NULL")
	}
}
