using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;

public class IntegrationInvoiceRequest
{
    [Required(ErrorMessage = "Invoice document number is required.")]
    [StringLength(10, ErrorMessage = "Invoice document number cannot exceed 10 characters.")]
    public string InvoiceDocumentNo { get; set; }

    [Required(ErrorMessage = "Invoice date is required.")]
    public DateTime InvoiceDate { get; set; }

    [Required(ErrorMessage = "Sales order reference number is required.")]
    [StringLength(13, ErrorMessage = "Sales order reference number cannot exceed 13 characters.")]
    public string SalesOrderRefNo { get; set; }

    [Required(ErrorMessage = "Delivery reference number is required.")]
    [StringLength(10, ErrorMessage = "Delivery reference number cannot exceed 10 characters.")]
    public string DeliveryRefNo { get; set; }

    [Required(ErrorMessage = "Invoice amount is required.")]
    [Range(typeof(decimal), "0.01", "999999999999.99",
        ErrorMessage = "Invoice amount must be greater than 0.")]
    public decimal InvoiceAmount { get; set; }

    [Required(ErrorMessage = "Invoice items are required.")]
    [MinLength(1, ErrorMessage = "At least one invoice item is required.")]
    public List<IntegrationInvoiceItemRequest> Items { get; set; } = new();
}


public class IntegrationInvoiceItemRequest
{
    [Required(ErrorMessage = "Material code is required.")]
    [RegularExpression(@".*\S.*", ErrorMessage = "Material code cannot be empty or whitespace.")]
    [StringLength(10, ErrorMessage = "Material code cannot exceed 10 characters.")]
    public string MaterialCode { get; set; }

    [Required(ErrorMessage = "Quantity is required.")]
    [Range(typeof(decimal), "0.01", "999999999999.99",
        ErrorMessage = "Quantity must be greater than 0.")]
    public decimal Quantity { get; set; }

    [Required(ErrorMessage = "Unit of measurement is required.")]
    [StringLength(10, ErrorMessage = "Unit of measurement cannot exceed 10 characters.")]
    public string UnitOfMeasurement { get; set; }
}
