package model

type Component interface {
	Weight() Weight
}

type SimpleComponent struct {
	name   string
	weight Weight
}

func NewSimpleComponent(name string, weight Weight) *SimpleComponent {
	return &SimpleComponent{name: name, weight: weight}
}

func (s *SimpleComponent) Weight() Weight {
	return s.weight
}

type CompoundComponent struct {
	name       string
	components []Component
}

func (tl *CompoundComponent) Weight() Weight {
	var w Weight = 0
	for _, component := range tl.components {
		w += component.Weight()
	}
	return w
}

func NewCompoundComponent(name string) *CompoundComponent {
	return &CompoundComponent{name: name}
}

func (tl *CompoundComponent) AddChildComponent(component Component) {
	tl.components = append(tl.components, component)
}
