package model

import "time"

type Training struct {
	name         string
	numberOfDays int
	dates        []TrainingInstance
}

func (t *Training) Name() string {
	return t.name
}

func (t *Training) NumberOfDays() int {
	return t.numberOfDays
}

func (t *Training) Dates() []TrainingInstance {
	return t.dates
}

func (t *Training) AssignTrainingInstances(trainings []TrainingInstance) {
	t.dates = trainings
}

func NewTrainingWithNumberOfDays(name string, numberOfDays int) *Training {
	return &Training{name: name, numberOfDays: numberOfDays}
}

type TrainingType string

const OnlineTrainingType = TrainingType("online")
const OnsiteTrainingType = TrainingType("onsite")

type TrainingInstance interface {
	Name() string
	StartTime() time.Time
	Type() TrainingType
}

type OnlineTraining struct {
	training  Training
	startTime time.Time
}

func (t OnlineTraining) Type() TrainingType {
	return OnlineTrainingType
}

func (t OnlineTraining) Name() string {
	return t.training.name
}

func (t OnlineTraining) StartTime() time.Time {
	return t.startTime
}

type OnsiteTraining struct {
	training  Training
	startTime time.Time
}

func (o OnsiteTraining) Type() TrainingType {
	return OnsiteTrainingType
}

func (o OnsiteTraining) Name() string {
	return o.training.name
}

func (o OnsiteTraining) StartTime() time.Time {
	return o.startTime
}

func NewTrainingInstance(training Training, trainingType TrainingType, startTime time.Time) TrainingInstance {

	switch trainingType {
	case OnlineTrainingType:
		return &OnlineTraining{training: training, startTime: startTime}
	case OnsiteTrainingType:
		return &OnsiteTraining{training: training, startTime: startTime}
	}
	return nil
}
