package impl

import (
	"ai_scheduler/internal/data/model"
	"ai_scheduler/tmpl/dataTemp"
	"ai_scheduler/utils"
	"database/sql"

	"xorm.io/builder"
)

type BotUserImpl struct {
	dataTemp.DataTemp
}

func NewBotUserImpl(db *utils.Db) *BotUserImpl {
	return &BotUserImpl{
		DataTemp: *dataTemp.NewDataTemp(db, new(model.AiBotUser)),
	}
}

func (k BotUserImpl) GetByStaffId(staffId string) (*model.AiBotUser, error) {
	var data model.AiBotUser
	err := k.Db.Model(k.Model).Where("staff_id = ?", staffId).Find(&data).Error
	if data.UserID == 0 {
		err = sql.ErrNoRows
	}
	return &data, err
}

func (k BotUserImpl) GetByUserIds(userIds []int32) ([]model.AiBotUser, error) {
	var data []model.AiBotUser
	cond := builder.NewCond()
	for _, userId := range userIds {
		cond = cond.Or(builder.Eq{"user_id": userId})
	}
	_, err := k.GetListToStruct(&cond, nil, &data, "user_id")

	return data, err
}
