package bunmodel

import (
	"fmt"

	"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
)

type Building struct {
	MaxLevel        int
	MinLevel        int
	Wood            int
	Stone           int
	Iron            int
	Pop             int
	WoodFactor      float64
	StoneFactor     float64
	IronFactor      float64
	PopFactor       float64
	BuildTime       float64
	BuildTimeFactor float64
}

type BuildingInfo struct {
	Main       Building
	Barracks   Building
	Stable     Building
	Garage     Building
	Watchtower Building
	Snob       Building
	Smith      Building
	Place      Building
	Statue     Building
	Market     Building
	Wood       Building
	Stone      Building
	Iron       Building
	Farm       Building
	Storage    Building
	Hide       Building
	Wall       Building
}

func NewBuildingInfo(info domain.BuildingInfo) BuildingInfo {
	return BuildingInfo{
		Main:       Building(info.Main()),
		Barracks:   Building(info.Barracks()),
		Stable:     Building(info.Stable()),
		Garage:     Building(info.Garage()),
		Watchtower: Building(info.Watchtower()),
		Snob:       Building(info.Snob()),
		Smith:      Building(info.Smith()),
		Place:      Building(info.Place()),
		Statue:     Building(info.Statue()),
		Market:     Building(info.Market()),
		Wood:       Building(info.Wood()),
		Stone:      Building(info.Stone()),
		Iron:       Building(info.Iron()),
		Farm:       Building(info.Farm()),
		Storage:    Building(info.Storage()),
		Hide:       Building(info.Hide()),
		Wall:       Building(info.Wall()),
	}
}

func (b BuildingInfo) ToDomain() (domain.BuildingInfo, error) {
	info, err := domain.NewBuildingInfo(
		domain.Building(b.Main),
		domain.Building(b.Barracks),
		domain.Building(b.Stable),
		domain.Building(b.Garage),
		domain.Building(b.Watchtower),
		domain.Building(b.Snob),
		domain.Building(b.Smith),
		domain.Building(b.Place),
		domain.Building(b.Statue),
		domain.Building(b.Market),
		domain.Building(b.Wood),
		domain.Building(b.Stone),
		domain.Building(b.Iron),
		domain.Building(b.Farm),
		domain.Building(b.Storage),
		domain.Building(b.Hide),
		domain.Building(b.Wall),
	)
	if err != nil {
		return domain.BuildingInfo{}, fmt.Errorf("couldn't construct domain.BuildingInfo: %w", err)
	}

	return info, nil
}
