package wait

import (
	"fmt"
	"time"
)

// from monday to friday from 12:00 utc to 22:00 utc
// saturday from 12:00 utc to 18:00 utc
// sunday wont work
func WaitAmount(actualTime time.Time) (infoDuration time.Duration, longDuration time.Duration) {
	var nextDayTime time.Time

	// day of the week start on sunday=0
	dayNumber := actualTime.UTC().Weekday()
	year, month, day, hour := actualTime.UTC().Year(), actualTime.UTC().Month(), actualTime.UTC().Day(), actualTime.UTC().Hour()
	nextDayTemplate := fmt.Sprintf("%d-%02d-%02d 12:05:00", year, month, day)
	parsedDate, err := time.Parse(time.DateTime, nextDayTemplate)
	if err != nil {
		panic(err)
	}
	// in case of waiting to next day or weekend
	switch dayNumber {
	case 0:
		nextDayTime = parsedDate.Add(24 * time.Hour)
		return time.Until(nextDayTime), time.Until(nextDayTime)
	case 6:
		if hour > 16 {
			nextDayTime = parsedDate.Add(48 * time.Hour)
			return time.Until(nextDayTime), time.Until(nextDayTime)
		} else {
			info := time.Until(actualTime.UTC().Add(26 * time.Minute))
			long := time.Until(actualTime.UTC().Add(59 * time.Minute))
			return info, long

		}
	default:
		nextDayTime = parsedDate.Add(24 * time.Hour)
		switch {
		case hour >= 22:
			// next day wait
			return time.Until(nextDayTime), time.Until(nextDayTime)
		case hour < 12:
			return time.Until(parsedDate), time.Until(parsedDate)
		default:
			info := time.Until(actualTime.UTC().Add(26 * time.Minute))
			long := time.Until(actualTime.UTC().Add(59 * time.Minute))
			return info, long
		}
	}
}
