using MongoDB.Bson.Serialization.Attributes;

namespace QRRapidoApp.Models
{
    /// <summary>
    /// Embedded document tracking the user's API subscription (separate from the QR credits plan).
    /// </summary>
    public class ApiSubscription
    {
        [BsonElement("tier")]
        public ApiPlanTier Tier { get; set; } = ApiPlanTier.Free;

        /// <summary>"free" | "active" | "past_due" | "canceled"</summary>
        [BsonElement("status")]
        public string Status { get; set; } = "free";

        [BsonElement("stripeSubscriptionId")]
        public string? StripeSubscriptionId { get; set; }

        [BsonElement("stripeCustomerId")]
        public string? StripeCustomerId { get; set; }

        [BsonElement("currentPeriodEnd")]
        public DateTime? CurrentPeriodEnd { get; set; }

        [BsonElement("activatedAt")]
        public DateTime? ActivatedAt { get; set; }

        [BsonElement("canceledAt")]
        public DateTime? CanceledAt { get; set; }

        public bool IsActive => Status == "active" && (CurrentPeriodEnd == null || CurrentPeriodEnd > DateTime.UtcNow);

        public ApiPlanTier EffectiveTier => IsActive ? Tier : ApiPlanTier.Free;
    }
}
