using Meezi.Core.Enums;

namespace Meezi.Core.Entities;

/// <summary>
/// Records a client-supplied Idempotency-Key so a retried write (e.g. an order
/// replayed from the offline outbox after a lost response) returns the original
/// result instead of executing twice. Standalone POCO — deliberately not a
/// TenantEntity, to avoid soft-delete/tenant query filters.
/// </summary>
public class IdempotencyRecord
{
    public string Id { get; set; } = Guid.NewGuid().ToString("N");

    /// <summary>Tenant scope (CafeId), or "global" for non-tenant requests.</summary>
    public string Scope { get; set; } = "global";

    /// <summary>The client-supplied Idempotency-Key header value.</summary>
    public string Key { get; set; } = string.Empty;

    public string Method { get; set; } = string.Empty;
    public string Path { get; set; } = string.Empty;

    public IdempotencyStatus Status { get; set; } = IdempotencyStatus.InProgress;

    public int ResponseStatusCode { get; set; }
    public string? ResponseBody { get; set; }

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime? CompletedAt { get; set; }
}
