using GraphQL.Types;

namespace Books.Api.GraphQL.InputTypes;

public class CreateOrderInputType : InputObjectGraphType<CreateOrderInput>
{
    public CreateOrderInputType()
    {
        Name = "CreateOrderInput";
        Description = "Input for creating a new order (Opret ordre)";

        Field(x => x.CompanyId).Description("Company ID (required)");
        Field(x => x.FiscalYearId).Description("Fiscal year ID (required)");
        Field(x => x.CustomerId).Description("Customer ID (required)");
        Field(x => x.OrderDate, nullable: true).Description("Order date (defaults to today)");
        Field(x => x.ExpectedDeliveryDate, nullable: true).Description("Expected delivery date");
        Field(x => x.VatCode, nullable: true).Description("Default VAT code for lines (defaults to U25)");
        Field(x => x.Notes, nullable: true).Description("Internal notes");
        Field(x => x.Reference, nullable: true).Description("Customer reference");
    }
}

public class CreateOrderInput
{
    public string CompanyId { get; set; } = string.Empty;
    public string FiscalYearId { get; set; } = string.Empty;
    public string CustomerId { get; set; } = string.Empty;
    public DateTime? OrderDate { get; set; }
    public DateTime? ExpectedDeliveryDate { get; set; }
    public string? VatCode { get; set; }
    public string? Notes { get; set; }
    public string? Reference { get; set; }
}

public class AddOrderLineInputType : InputObjectGraphType<AddOrderLineInput>
{
    public AddOrderLineInputType()
    {
        Name = "AddOrderLineInput";
        Description = "Input for adding a line to an order (Tilføj ordrelinje)";

        Field(x => x.OrderId).Description("Order ID (required)");
        Field(x => x.ProductId, nullable: true).Description("Product ID (optional, for linking to a product)");
        Field(x => x.Description).Description("Description of product/service (required)");
        Field(x => x.Quantity).Description("Quantity (required, must be positive)");
        Field(x => x.UnitPrice).Description("Unit price excluding VAT (required)");
        Field(x => x.VatCode, nullable: true).Description("VAT code (defaults to U25)");
        Field(x => x.AccountId, nullable: true).Description("Revenue account ID (defaults to customer's default)");
        Field(x => x.Unit, nullable: true).Description("Unit of measurement (e.g., stk, timer)");
        Field(x => x.DiscountPercent, nullable: true).Description("Discount percentage (0-100)");
    }
}

public class AddOrderLineInput
{
    public string OrderId { get; set; } = string.Empty;
    public string? ProductId { get; set; }
    public string Description { get; set; } = string.Empty;
    public decimal Quantity { get; set; }
    public decimal UnitPrice { get; set; }
    public string? VatCode { get; set; }
    public string? AccountId { get; set; }
    public string? Unit { get; set; }
    public decimal? DiscountPercent { get; set; }
}

public class UpdateOrderLineInputType : InputObjectGraphType<UpdateOrderLineInput>
{
    public UpdateOrderLineInputType()
    {
        Name = "UpdateOrderLineInput";
        Description = "Input for updating a line on an order (Opdater ordrelinje)";

        Field(x => x.OrderId).Description("Order ID (required)");
        Field(x => x.LineNumber).Description("Line number to update (required)");
        Field(x => x.ProductId, nullable: true).Description("Product ID (optional)");
        Field(x => x.Description).Description("Description of product/service (required)");
        Field(x => x.Quantity).Description("Quantity (required)");
        Field(x => x.UnitPrice).Description("Unit price excluding VAT (required)");
        Field(x => x.VatCode, nullable: true).Description("VAT code");
        Field(x => x.AccountId, nullable: true).Description("Revenue account ID");
        Field(x => x.Unit, nullable: true).Description("Unit of measurement");
        Field(x => x.DiscountPercent, nullable: true).Description("Discount percentage (0-100)");
    }
}

public class UpdateOrderLineInput
{
    public string OrderId { get; set; } = string.Empty;
    public int LineNumber { get; set; }
    public string? ProductId { get; set; }
    public string Description { get; set; } = string.Empty;
    public decimal Quantity { get; set; }
    public decimal UnitPrice { get; set; }
    public string? VatCode { get; set; }
    public string? AccountId { get; set; }
    public string? Unit { get; set; }
    public decimal? DiscountPercent { get; set; }
}

public class RemoveOrderLineInputType : InputObjectGraphType<RemoveOrderLineInput>
{
    public RemoveOrderLineInputType()
    {
        Name = "RemoveOrderLineInput";
        Description = "Input for removing a line from an order (Fjern ordrelinje)";

        Field(x => x.OrderId).Description("Order ID (required)");
        Field(x => x.LineNumber).Description("Line number to remove (required)");
    }
}

public class RemoveOrderLineInput
{
    public string OrderId { get; set; } = string.Empty;
    public int LineNumber { get; set; }
}

public class ConfirmOrderInputType : InputObjectGraphType<ConfirmOrderInput>
{
    public ConfirmOrderInputType()
    {
        Name = "ConfirmOrderInput";
        Description = "Input for confirming an order (Bekræft ordre)";

        Field(x => x.OrderId).Description("Order ID (required)");
    }
}

public class ConfirmOrderInput
{
    public string OrderId { get; set; } = string.Empty;
}

public class InvoiceOrderLinesInputType : InputObjectGraphType<InvoiceOrderLinesInput>
{
    public InvoiceOrderLinesInputType()
    {
        Name = "InvoiceOrderLinesInput";
        Description = "Input for invoicing order lines (Fakturer ordrelinjer)";

        Field(x => x.OrderId).Description("Order ID (required)");
        Field<NonNullGraphType<ListGraphType<NonNullGraphType<IntGraphType>>>>("lineNumbers")
            .Description("Line numbers to include in the invoice (required, empty for all uninvoiced lines)");
        Field(x => x.InvoiceDate, nullable: true).Description("Invoice date (defaults to today)");
        Field(x => x.DueDate, nullable: true).Description("Due date (defaults based on payment terms)");
    }
}

public class InvoiceOrderLinesInput
{
    public string OrderId { get; set; } = string.Empty;
    public List<int> LineNumbers { get; set; } = [];
    public DateTime? InvoiceDate { get; set; }
    public DateTime? DueDate { get; set; }
}

public class CancelOrderInputType : InputObjectGraphType<CancelOrderInput>
{
    public CancelOrderInputType()
    {
        Name = "CancelOrderInput";
        Description = "Input for cancelling an order (Annuller ordre)";

        Field(x => x.OrderId).Description("Order ID (required)");
        Field(x => x.Reason).Description("Reason for cancellation (required)");
    }
}

public class CancelOrderInput
{
    public string OrderId { get; set; } = string.Empty;
    public string Reason { get; set; } = string.Empty;
}
