#nullable enable
using Baya.Domain.Common;

namespace Baya.Domain.Entities.Payments;

/// <summary>
/// Config per connected PSP/BNPL provider — the unit of <b>selection and failover</b>. The active
/// <c>standard</c> gateway with the lowest <see cref="Priority"/> is chosen for a card capture, so a
/// cut-off provider (Toman/Jibit were abruptly suspended Nov 2024) is swapped <b>by config, not a code
/// change</b>. <see cref="ConfigJson"/> holds provider-selection/failover config (merchant id, terminal/IBAN
/// registration for the تسهیم split, base url, sandbox flag) — <b>never per-transaction credentials</b> — and
/// is <b>encrypted at rest</b> through the field encryptor and never logged in plaintext.
/// </summary>
public class PaymentGateway : BaseEntity<long>
{
    /// <summary>Provider code — <c>zarinpal</c> / <c>sadad</c> / <c>vandar</c> / <c>jibit</c> …</summary>
    public string ProviderCode { get; set; } = null!;

    /// <summary>A <see cref="PaymentGatewayType"/> code — selects the card (<c>standard</c>) vs BNPL flow.</summary>
    public string Type { get; set; } = PaymentGatewayType.Standard;

    public string DisplayName { get; set; } = null!;

    /// <summary>Encrypted provider-selection/failover config (merchant id, terminal/IBAN registration, base
    /// url, sandbox flag). Encrypted at rest via <c>IFieldEncryptor</c>; never per-transaction credentials.</summary>
    public string ConfigJson { get; set; } = null!;

    public bool IsActive { get; set; } = true;

    /// <summary>Failover order — the active gateway of a type with the lowest priority wins selection.</summary>
    public int Priority { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
}
