using System.Text.Json.Serialization;

namespace KArtSell.Modules.ModelOperations.ShadowRun.Features.ImportMarketData;

/// <summary>
/// Command to import market data from external APIs (KRX, OpenDart, KIS).
/// Idempotent: can be safely replayed.
/// </summary>
public class ImportMarketDataCommand
{
    [JsonPropertyName("apiName")]
    public string ApiName { get; set; } = "";  // 'krx', 'opendart', 'kis'

    [JsonPropertyName("importDate")]
    public DateOnly ImportDate { get; set; }

    [JsonPropertyName("parameters")]
    public Dictionary<string, string> Parameters { get; set; } = new();

    [JsonPropertyName("idempotencyKey")]
    public Guid IdempotencyKey { get; set; } = Guid.NewGuid();

    [JsonPropertyName("correlationId")]
    public Guid CorrelationId { get; set; } = Guid.NewGuid();

    [JsonPropertyName("retryCount")]
    public int RetryCount { get; set; } = 0;

    public ImportMarketDataCommand() { }

    public ImportMarketDataCommand(
        string apiName,
        DateOnly importDate,
        Dictionary<string, string>? parameters = null,
        Guid? idempotencyKey = null,
        Guid? correlationId = null)
    {
        ApiName = apiName;
        ImportDate = importDate;
        Parameters = parameters ?? new();
        IdempotencyKey = idempotencyKey ?? Guid.NewGuid();
        CorrelationId = correlationId ?? Guid.NewGuid();
    }
}
