package common

import "errors"

var ErrInvalidType = errors.New("invalid type")

type MobileDepartureSchedule struct {
	VIN               string            `json:"vin" validate:"required,vin"`
	DepartureSchedule DepartureSchedule `json:"departure_schedule" validate:"required"`
}

func (m *MobileDepartureSchedule) SetVIN(vin string) {
	m.VIN = vin
}

func (m *MobileDepartureSchedule) SetPayload(payload interface{}) error {
	var ok bool
	m.DepartureSchedule, ok = payload.(DepartureSchedule)
	if !ok {
		return ErrInvalidType
	}

	return nil
}

func (m *MobileDepartureSchedule) GetVIN() string {
	return m.VIN
}

func (m *MobileDepartureSchedule) GetPayload() interface{} {
	return m.DepartureSchedule
}

type TRexDepartureSchedule = DepartureSchedule

type DepartureSchedule struct {
	NextDayDeparture *string        `json:"next_day_departure,omitempty" validate:"required_without=DepartureDays"`
	DepartureDays    []DepartureDay `json:"departure_days,omitempty"`
}

type DepartureDay struct {
	DayOfWeek string `json:"day_of_week" validate:"oneof=Mon Tue Wed Thu Fri Sat Sun"`
	Time      string `json:"time" validate:"datetime=15:04"`
}

func (m *TRexDepartureSchedule) SetPayload(payload interface{}) error {
	var ok bool
	*m, ok = payload.(DepartureSchedule)
	if !ok {
		return ErrInvalidType
	}

	return nil
}

func (m *TRexDepartureSchedule) GetMessage() interface{} {
	return m
}

func (m *TRexDepartureSchedule) GetPayload() interface{} {
	return *m
}
