using Books.Api.Domain.Customers;
using Books.Api.GraphQL.Types;
using GraphQL.Types;

namespace Books.Api.GraphQL.InputTypes;

public class CreateCustomerInputType : InputObjectGraphType<CreateCustomerInput>
{
    public CreateCustomerInputType()
    {
        Name = "CreateCustomerInput";
        Description = "Input for creating a new customer";

        Field(x => x.CompanyId).Description("Company ID (required)");
        Field<NonNullGraphType<CustomerTypeEnumType>>("customerType")
            .Description("Customer type: BUSINESS or PRIVATE (required)");
        Field(x => x.Name).Description("Customer name (required)");
        Field(x => x.Cvr, nullable: true).Description("CVR number (required for BUSINESS customers)");
        Field(x => x.Address, nullable: true).Description("Street address");
        Field(x => x.PostalCode, nullable: true).Description("Postal code");
        Field(x => x.City, nullable: true).Description("City");
        Field(x => x.Country, nullable: true).Description("Country code (ISO 2-letter, default: DK)");
        Field(x => x.Email, nullable: true).Description("Email address");
        Field(x => x.Phone, nullable: true).Description("Phone number");
        Field(x => x.PaymentTermsDays, nullable: true).Description("Payment terms in days (default: 30)");
        Field(x => x.DefaultRevenueAccountId, nullable: true).Description("Default revenue account for invoices");
    }
}

public class CreateCustomerInput
{
    public string CompanyId { get; set; } = string.Empty;
    public CustomerType CustomerType { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Cvr { get; set; }
    public string? Address { get; set; }
    public string? PostalCode { get; set; }
    public string? City { get; set; }
    public string? Country { get; set; }
    public string? Email { get; set; }
    public string? Phone { get; set; }
    public int? PaymentTermsDays { get; set; }
    public string? DefaultRevenueAccountId { get; set; }
}

public class UpdateCustomerInputType : InputObjectGraphType<UpdateCustomerInput>
{
    public UpdateCustomerInputType()
    {
        Name = "UpdateCustomerInput";
        Description = "Input for updating a customer";

        Field(x => x.Id).Description("Customer ID (required)");
        Field(x => x.Name).Description("Customer name (required)");
        Field(x => x.Cvr, nullable: true).Description("CVR number (required for BUSINESS customers)");
        Field(x => x.Address, nullable: true).Description("Street address");
        Field(x => x.PostalCode, nullable: true).Description("Postal code");
        Field(x => x.City, nullable: true).Description("City");
        Field(x => x.Country, nullable: true).Description("Country code (ISO 2-letter, default: DK)");
        Field(x => x.Email, nullable: true).Description("Email address");
        Field(x => x.Phone, nullable: true).Description("Phone number");
        Field(x => x.PaymentTermsDays, nullable: true).Description("Payment terms in days");
        Field(x => x.DefaultRevenueAccountId, nullable: true).Description("Default revenue account for invoices");
    }
}

public class UpdateCustomerInput
{
    public string Id { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public string? Cvr { get; set; }
    public string? Address { get; set; }
    public string? PostalCode { get; set; }
    public string? City { get; set; }
    public string? Country { get; set; }
    public string? Email { get; set; }
    public string? Phone { get; set; }
    public int? PaymentTermsDays { get; set; }
    public string? DefaultRevenueAccountId { get; set; }
}
