#include "BuildingType.h"

std::optional<BuildingType> parseBuildingType(const std::string& id)
{
    if (id == "miner")                { return BuildingType::Miner; }
    if (id == "smelter")              { return BuildingType::Smelter; }
    if (id == "assembler")            { return BuildingType::Assembler; }
    if (id == "reprocessing_plant")   { return BuildingType::ReprocessingPlant; }
    if (id == "shipyard")             { return BuildingType::Shipyard; }
    if (id == "salvage_bay")          { return BuildingType::SalvageBay; }
    if (id == "belt")                 { return BuildingType::Belt; }
    if (id == "splitter")             { return BuildingType::Splitter; }
    if (id == "tunnel_entry")         { return BuildingType::TunnelEntry; }
    if (id == "tunnel_exit")          { return BuildingType::TunnelExit; }
    if (id == "hq")                   { return BuildingType::Hq; }
    if (id == "player_defence_station") { return BuildingType::PlayerDefenceStation; }
    if (id == "enemy_defence_station")  { return BuildingType::EnemyDefenceStation; }
    return std::nullopt;
}

std::string buildingTypeId(BuildingType type)
{
    switch (type)
    {
        case BuildingType::Miner:                return "miner";
        case BuildingType::Smelter:              return "smelter";
        case BuildingType::Assembler:            return "assembler";
        case BuildingType::ReprocessingPlant:    return "reprocessing_plant";
        case BuildingType::Shipyard:             return "shipyard";
        case BuildingType::SalvageBay:           return "salvage_bay";
        case BuildingType::Belt:                 return "belt";
        case BuildingType::Splitter:             return "splitter";
        case BuildingType::TunnelEntry:          return "tunnel_entry";
        case BuildingType::TunnelExit:           return "tunnel_exit";
        case BuildingType::Hq:                   return "hq";
        case BuildingType::PlayerDefenceStation: return "player_defence_station";
        case BuildingType::EnemyDefenceStation:  return "enemy_defence_station";
    }
    return "";
}

bool isAutoRecipeBuildingType(BuildingType type)
{
    return type == BuildingType::Smelter
        || type == BuildingType::ReprocessingPlant;
}

bool isBeltSubsystemType(BuildingType type)
{
    return type == BuildingType::Belt
        || type == BuildingType::Splitter
        || type == BuildingType::TunnelEntry
        || type == BuildingType::TunnelExit;
}

bool isConfigurableBuildingType(BuildingType type)
{
    switch (type)
    {
    case BuildingType::Miner:      // recipe (REQ-BLD-MINER)
    case BuildingType::Assembler:  // recipe (REQ-BLD-ASSEMBLER)
    case BuildingType::Smelter:           // recipe (REQ-BLD-AUTO-RECIPE)
    case BuildingType::ReprocessingPlant:  // recipe (REQ-BLD-AUTO-RECIPE)
    case BuildingType::Shipyard:   // schematic and layout (REQ-BLD-SHIPYARD, REQ-MOD-LAYOUT)
    case BuildingType::Splitter:   // output filters (REQ-BLD-SPLITTER)
        return true;
    default:
        return false;
    }
}

bool isProductionBuildingType(BuildingType type)
{
    switch (type)
    {
    case BuildingType::Miner:
    case BuildingType::Smelter:
    case BuildingType::Assembler:
    case BuildingType::ReprocessingPlant:
    case BuildingType::Shipyard:
        return true;
    default:
        return false;
    }
}
