package cif

import (
	"errors"
	"time"

	"git.fjla.uk/owlboard/timetable-mgr/log"
	"go.uber.org/zap"
)

// Fetches the day string for TODAYs update.  Needs adjusting to be able to accept a time.Time type and return the day string for that day
func getDayString() string {
	london, err := time.LoadLocation("Europe/London")
	if err != nil {
		log.Msg.Error("Unable to load time zone info", zap.Error(err))
	}

	timeNow := time.Now().In(london)
	day := timeNow.Weekday()

	dayStrings := [...]string{"sun", "mon", "tue", "wed", "thu", "fri", "sat"}

	return dayStrings[day]
}

// Simply returns the correct URL for either a 'daily' or 'full' update.
func getUpdateUrl(updateType string) (string, error) {
	if updateType == "daily" {
		return dailyUpdateUrl + getDayString(), nil
	} else if updateType == "full" {
		return fullUpdateUrl, nil
	}
	err := errors.New("invalid update type provided, must be one of 'daily' or 'full'")
	return "", err
}
