package repository

import (
	"bpmsapi/entity"
	"log"

	"github.com/jmoiron/sqlx"
)

type TimeSlotActions interface {
	FetchAvailableTimeSlot(input entity.GetTimeSlotInput) ([]entity.TimeSlot, error)
}

type TimeSlotRepository struct {
	trans *sqlx.Tx
}

func TimeSlotRepositoryInit(trans *sqlx.Tx) *TimeSlotRepository {
	return &TimeSlotRepository{
		trans: trans,
	}
}

func (timeslotRepo *TimeSlotRepository) FetchAvailableTimeSlot(input entity.GetTimeSlotInput) (timeslots []entity.TimeSlot, err error) {
	err = timeslotRepo.trans.Select(&timeslots, "SELECT `Slot_Date`, `Slot_01`, `Slot_02`, `Slot_03`, `Slot_04`, `Slot_05`, `Slot_06`, `Slot_07`, `Slot_08`, `Slot_09`, `Slot_10`, `Slot_11`, `Slot_12`, `Slot_13`, `Slot_14`, `Slot_15`, `Slot_16`, `Slot_17`, `Slot_18`, `Slot_19`, `Slot_20`, `Slot_21`, `Slot_22`, `Slot_23`, `Slot_24`, `Apartment_Id`, `Rec_Timestamp` FROM `BPMS_TIME_SLOT` WHERE Apartment_Id=? and Slot_Date >= DATE(?)", input.Apartment_Id, input.Date)
	if err != nil {
		log.Print("TimeSlotRepository: FetchAvailableTimeSlot: gettingtimeslots: input: ", input.Date, " Error: ", err.Error())
		return nil, err
	} else {
		return timeslots, nil
	}

}
