package common

import "time"

type OffPeakCharging struct {
	Start time.Time `json:"start" validate:"required"`
	End   time.Time `json:"end" validate:"required"`
}

type MobileChargeSetting struct {
	VIN            string         `json:"vin" validate:"required,vin"`
	ChargeSettings ChargeSettings `json:"charge_settings" validate:"required"`
}

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

func (m *MobileChargeSetting) GetPayload() interface{} {
	return m.ChargeSettings
}

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

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

	return nil
}

type TRexChargeSettings = ChargeSettings

type ChargeSettings struct {
	ChargeLimit     int              `json:"charge_limit" validate:"required"`
	MaxCurrent      int              `json:"max_current" validate:"required"`
	MinCharge       *int             `json:"min_charge,omitempty"`
	OffPeakCharging *OffPeakCharging `json:"off_peak_charging,omitempty"`
}

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

	return nil
}

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

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