namespace Theriapolis.Core.World;

public enum NarrativeAnchor : byte
{
    Millhaven, Thornfield, FortDustwall, TheTangles,
    SanctumFidelis, Heartstone
}

public enum SettlementEconomy : byte
{
    Farming, Mining, Manufacturing, Trade, Military, Fishing
}

public enum SettlementGovernance : byte
{
    Council, Mayor, MilitaryCommandant, ClanElder, Corporate, Anarchic
}

public enum PoiType : byte
{
    None, ImperiumRuin, AbandonedMine, CultDen, NaturalCave, OvergrownSettlement
}

/// <summary>
/// A placed settlement or point of interest on the world map.
/// Tier 1–4 are inhabited settlements; Tier 5 are PoIs (IsPoi == true).
/// </summary>
public sealed class Settlement
{
    public int    Id         { get; init; }
    public string Name       { get; set; } = "";
    public int    Tier       { get; init; }
    public int    TileX      { get; init; }
    public int    TileY      { get; init; }

    /// <summary>World-pixel X (tile center).</summary>
    public float WorldPixelX => TileX * C.WORLD_TILE_PIXELS + C.WORLD_TILE_PIXELS * 0.5f;
    /// <summary>World-pixel Y (tile center).</summary>
    public float WorldPixelY => TileY * C.WORLD_TILE_PIXELS + C.WORLD_TILE_PIXELS * 0.5f;

    /// <summary>Narrative anchor this settlement fulfills, or null for non-anchors.</summary>
    public NarrativeAnchor? Anchor { get; init; }

    // ── Generated attributes (set by SettlementAttributesStage) ─────────────
    public SettlementEconomy    Economy     { get; set; }
    public SettlementGovernance Governance  { get; set; }
    public string[]             CladeRatios { get; set; } = Array.Empty<string>();
    public float                WealthLevel { get; set; }
    public int                  Population  { get; set; }
    public float                HybridPct   { get; set; }
    public string               ScentProfile { get; set; } = "";

    // ── Derived after infrastructure gen ────────────────────────────────────
    public bool HasRailStation { get; set; }
    public bool IsOnRiver      { get; set; }

    // ── PoI-specific ─────────────────────────────────────────────────────────
    public bool    IsPoi   { get; init; }
    public PoiType PoiType { get; set; }

    // ── Phase 6 M0 — building footprints ────────────────────────────────────
    /// <summary>
    /// Buildings stamped inside this settlement, derived deterministically
    /// from the matched <see cref="Data.SettlementLayoutDef"/>. Populated
    /// lazily by <see cref="Settlements.SettlementStamper"/> on first chunk
    /// generation that touches this settlement; identical across reloads.
    /// </summary>
    public List<Settlements.BuildingFootprint> Buildings { get; } = new();

    /// <summary>True once <see cref="Buildings"/> has been resolved.</summary>
    public bool BuildingsResolved { get; set; }
}
