package client

import (
	"galaxy/client/world"
	"galaxy/model/report"
)

const (
	entityClassUnknown int = iota - 1
	entityClassLocalPlanet
	entityClassOthersPlanet
	entityClassFreePlanet
	entityClassUnidentifiedPlanet
)

type registry struct {
	report                  *report.Report
	localPlanetIndex        map[world.PrimitiveID]int
	unidentifiedPlanetIndex map[world.PrimitiveID]int
}

func newRegistry() *registry {
	return &registry{
		localPlanetIndex:        make(map[world.PrimitiveID]int),
		unidentifiedPlanetIndex: make(map[world.PrimitiveID]int),
	}
}

func (r *registry) clear(report *report.Report) {
	r.report = report
	clear(r.localPlanetIndex)
	clear(r.unidentifiedPlanetIndex)
}

func (r *registry) entityClass(id world.PrimitiveID) int {
	if r.isLocalPlanet(id) {
		return entityClassLocalPlanet
	}
	if r.isUnidentifiedPlanet(id) {
		return entityClassUnidentifiedPlanet
	}
	return entityClassUnknown
}

func (r *registry) registerLocalPlanet(id world.PrimitiveID, index int) {
	r.localPlanetIndex[id] = index
}

func (r *registry) isLocalPlanet(id world.PrimitiveID) bool {
	_, ok := r.localPlanetIndex[id]
	return ok
}

func (r *registry) localPlanet(id world.PrimitiveID) (*report.LocalPlanet, bool) {
	i, ok := r.localPlanetIndex[id]
	if !ok {
		return nil, false
	}
	if i > len(r.report.LocalPlanet)-1 {
		return nil, false
	}
	return &r.report.LocalPlanet[i], true
}

func (r *registry) registerUnidentifiedPlanet(id world.PrimitiveID, index int) {
	r.unidentifiedPlanetIndex[id] = index
}

func (r *registry) isUnidentifiedPlanet(id world.PrimitiveID) bool {
	_, ok := r.unidentifiedPlanetIndex[id]
	return ok
}

func (c *client) createShipClass(n string, D float64, A uint, W float64, S float64, C float64) {

}
