using System.Text.Json.Serialization;

namespace NeonSprawl.Server.Game.Interaction;

/// <summary>JSON body for every handled interaction attempt (HTTP 200 only; NS-18).</summary>
/// <remarks>
/// When <see cref="Allowed"/> is <c>false</c>, <see cref="ReasonCode"/> is required and must be non-empty.
/// When <see cref="Allowed"/> is <c>true</c>, omit <see cref="ReasonCode"/>; <see cref="Payload"/> is optional.
/// Unknown player → HTTP 404 (no body). Malformed v1 request → HTTP 400.
/// </remarks>
public sealed class InteractionResponse
{
    public const int CurrentSchemaVersion = 1;

    [JsonPropertyName("schemaVersion")]
    public int SchemaVersion { get; init; } = CurrentSchemaVersion;

    [JsonPropertyName("allowed")]
    public bool Allowed { get; init; }

    /// <summary>Stable machine string when denied; omitted when allowed.</summary>
    [JsonPropertyName("reasonCode")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? ReasonCode { get; init; }

    /// <summary>Echo canonical id on success; omitted when denied.</summary>
    [JsonPropertyName("interactableId")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? InteractableId { get; init; }

    [JsonPropertyName("payload")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public InteractionPlaceholderPayload? Payload { get; init; }
}

/// <summary>Placeholder success payload for prototype wiring.</summary>
public sealed class InteractionPlaceholderPayload
{
    [JsonPropertyName("kind")]
    public string Kind { get; init; } = "placeholder";
}
