using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Lada.Framework.Data.Domains.BaseEntities;
using Lada.Framework.Data.Domains.Crm;
using Lada.Framework.Data.Domains.Medias;

namespace Lada.Framework.Data.Domains.Finance
{
    /// <summary>
    /// Hóa đơn thuế cho phiếu đối soát khách hàng
    /// </summary>
    public class TaxInvoice : BaseEntityWithKey<int>
    {
        /// <summary>
        /// ID phiếu đối soát
        /// </summary>
        [Required]
        public int CustomerReconciliationSlipId { get; set; }

        /// <summary>
        /// ID thông tin VAT
        /// </summary>
        [Required]
        public int VatInfoId { get; set; }

        /// <summary>
        /// Số hóa đơn
        /// </summary>
        [MaxLength(50)]
        public string InvoiceNumber { get; set; } = string.Empty;

        /// <summary>
        /// Ngày xuất hóa đơn
        /// </summary>
        public DateTimeOffset? InvoiceDate { get; set; }

        /// <summary>
        /// Trạng thái hóa đơn
        /// </summary>
        public TaxInvoiceStatus Status { get; set; } = TaxInvoiceStatus.NotIssued;

        /// <summary>
        /// Tổng tiền trước thuế
        /// </summary>
        public decimal TotalAmount { get; set; }

        /// <summary>
        /// Tiền thuế VAT
        /// </summary>
        public decimal VatAmount { get; set; }

        /// <summary>
        /// Tổng tiền sau thuế
        /// </summary>
        public decimal TotalAmountIncludingVat { get; set; }

        /// <summary>
        /// Thuế suất (%)
        /// </summary>
        public decimal VatRate { get; set; } = 10; // Default 10%

        /// <summary>
        /// ID media (file PDF hóa đơn)
        /// </summary>
        public Guid? MediaId { get; set; }

        /// <summary>
        /// Ghi chú
        /// </summary>
        [MaxLength(2048)]
        public string Note { get; set; } = string.Empty;

        #region Navigation Properties

        /// <summary>
        /// Phiếu đối soát
        /// </summary>
        public virtual CustomerReconciliationSlip CustomerReconciliationSlip { get; set; }

        /// <summary>
        /// Thông tin VAT
        /// </summary>
        public virtual VatInfo VatInfo { get; set; }

        /// <summary>
        /// File PDF hóa đơn
        /// </summary>
        public virtual Media? Media { get; set; }

        #endregion
    }

    /// <summary>
    /// Trạng thái hóa đơn thuế
    /// </summary>
    public enum TaxInvoiceStatus
    {
        [Description("Chưa xuất")]
        NotIssued = 1,

        [Description("Nháp")]
        Draft = 2,

        [Description("Đã xuất")]
        Issued = 3
    }
}
