using System.Text.Json.Serialization;

namespace Theriapolis.Core.Data;

/// <summary>
/// Loot table — list of weighted drop entries rolled when an NPC with
/// matching <see cref="NpcTemplateDef.LootTable"/> id falls in combat.
/// Each drop entry rolls independently against its <see cref="LootDrop.Chance"/>;
/// successful drops contribute (qty_min..qty_max) of the item.
///
/// Phase 5 M6 keeps this stingy by design — most level-1 fights net 1-3
/// items at most, never enough to obsolete the starting kit.
/// </summary>
public sealed record LootTableDef
{
    [JsonPropertyName("id")]
    public string Id { get; init; } = "";

    [JsonPropertyName("drops")]
    public LootDrop[] Drops { get; init; } = System.Array.Empty<LootDrop>();
}

public sealed record LootDrop
{
    [JsonPropertyName("item_id")]
    public string ItemId { get; init; } = "";

    [JsonPropertyName("qty_min")]
    public int QtyMin { get; init; } = 1;

    [JsonPropertyName("qty_max")]
    public int QtyMax { get; init; } = 1;

    /// <summary>0..1 probability this drop fires. Independent of other drops in the table.</summary>
    [JsonPropertyName("chance")]
    public float Chance { get; init; } = 1.0f;
}
