using Meezi.Core.Enums;

namespace Meezi.Core.Entities;

public class Order : TenantEntity
{
    public string? BranchId { get; set; }
    public string? TableId { get; set; }
    public string? ReservationId { get; set; }
    /// <summary>Walk-in label at POS when no CRM customer is linked.</summary>
    public string? GuestName { get; set; }
    public string? GuestPhone { get; set; }
    public string? CustomerId { get; set; }
    public string? EmployeeId { get; set; }
    public OrderType OrderType { get; set; }
    public OrderSource Source { get; set; } = OrderSource.Pos;
    public OrderStatus Status { get; set; } = OrderStatus.Pending;
    /// <summary>Human-facing order number (digits only), unique per cafe.</summary>
    public int DisplayNumber { get; set; }
    public DateTime StatusUpdatedAt { get; set; } = DateTime.UtcNow;
    /// <summary>Secret token for guest order tracking (QR) without login.</summary>
    public string? GuestTrackingToken { get; set; }
    public string? CouponId { get; set; }
    public decimal DiscountAmount { get; set; }
    public decimal Subtotal { get; set; }
    public decimal TaxTotal { get; set; }
    public decimal Total { get; set; }
    public string? SnappfoodOrderId { get; set; }
    /// <summary>External order id from delivery platform (Snappfood, Tap30, etc.).</summary>
    public string? ExternalOrderId { get; set; }
    public DeliveryPlatform? DeliveryPlatform { get; set; }
    /// <summary>Platform commission amount deducted from gross (stored for finance reports).</summary>
    public decimal PlatformCommission { get; set; }
    /// <summary>JSON snapshot: driver, address, delivery ETA, etc.</summary>
    public string? DeliveryMetaJson { get; set; }

    /// <summary>Reason captured when the order was cancelled (POS audit / accountability).</summary>
    public string? CancelReason { get; set; }
    /// <summary>Employee who cancelled the order (null for system/automated).</summary>
    public string? CancelledByEmployeeId { get; set; }
    public DateTime? CancelledAt { get; set; }

    public Cafe Cafe { get; set; } = null!;
    public Branch? Branch { get; set; }
    public Table? Table { get; set; }
    public TableReservation? Reservation { get; set; }
    public Customer? Customer { get; set; }
    public Employee? Employee { get; set; }
    public Coupon? Coupon { get; set; }
    public ICollection<OrderItem> Items { get; set; } = [];
    public ICollection<Payment> Payments { get; set; } = [];
}
