package main

import "time"

const (
	MatchStatusQueuing           = "queuing"
	MatchStatusMatched           = "matched"
	MatchStatusServerStarting    = "server_starting"
	MatchStatusWaitingForPlayers = "waiting_for_players"
	MatchStatusKnifeRound        = "knife_round"
	MatchStatusSideSelection     = "side_selection"
	MatchStatusLive              = "live"
	MatchStatusFinished          = "finished"
	MatchStatusAborted           = "aborted"
	MatchStatusCancelled         = "cancelled"
	MatchStatusCleanup           = "cleanup"
)

const (
	ServerStatusStarting = "starting"
	ServerStatusReady    = "ready"
	ServerStatusLive     = "live"
	ServerStatusStopping = "stopping"
	ServerStatusStopped  = "stopped"
)

type Match struct {
	ID            string         `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
	GameMode      string         `gorm:"type:varchar(32);not null" json:"game_mode"`
	Map           string         `gorm:"type:varchar(64);not null" json:"map"`
	Status        string         `gorm:"type:varchar(32);not null" json:"status"`
	ServerID      *string        `gorm:"type:uuid" json:"server_id"`
	Team1Name     string         `gorm:"type:varchar(64);default:'Team Alpha'" json:"team1_name"`
	Team2Name     string         `gorm:"type:varchar(64);default:'Team Beta'" json:"team2_name"`
	Team1Score    int            `gorm:"default:0" json:"team1_score"`
	Team2Score    int            `gorm:"default:0" json:"team2_score"`
	ConnectString *string        `gorm:"type:varchar(255)" json:"connect_string"`
	CreatedAt     time.Time      `gorm:"not null" json:"created_at"`
	StartedAt     *time.Time     `json:"started_at"`
	FinishedAt    *time.Time     `json:"finished_at"`
}

func (Match) TableName() string {
	return "matches"
}

type GameServer struct {
	ID            string     `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
	MatchID       *string    `gorm:"type:uuid" json:"match_id"`
	ContainerID   string     `gorm:"type:varchar(64);not null" json:"container_id"`
	ContainerName string     `gorm:"type:varchar(128);not null" json:"container_name"`
	Host          string     `gorm:"type:varchar(255);not null" json:"host"`
	Port          int        `gorm:"not null" json:"port"`
	RCONPassword  string     `gorm:"type:varchar(64);not null" json:"rcon_password"`
	GSLTToken     string     `gorm:"type:varchar(64);not null" json:"gslt_token"`
	Status        string     `gorm:"type:varchar(32);not null" json:"status"`
	CreatedAt     time.Time  `gorm:"not null" json:"created_at"`
	StoppedAt     *time.Time `json:"stopped_at"`
}

func (GameServer) TableName() string {
	return "game_servers"
}

type PortPool struct {
	Port      int     `gorm:"primaryKey" json:"port"`
	Allocated bool    `gorm:"default:false" json:"allocated"`
	ServerID  *string `gorm:"type:uuid" json:"server_id"`
}

func (PortPool) TableName() string {
	return "port_pool"
}

type GSLTAllocation struct {
	Token     string
	Allocated bool
	ServerID  string
}
