// ============================================================
// Lexware Office API - TypeScript Interfaces
// ============================================================
// Basiert auf: https://developers.lexware.io/docs/
// ============================================================

// --------------------------------------------------------
// Contact Interfaces
// --------------------------------------------------------

export interface LexwareContactPerson {
  salutation?: string;
  firstName?: string;
  lastName?: string;
}

export interface LexwareContactCompany {
  name?: string;
  taxNumber?: string;
  vatRegistrationId?: string;
  allowTaxFreeInvoices?: boolean;
  contactPersons?: LexwareContactPersonEntry[];
}

export interface LexwareContactPersonEntry {
  salutation?: string;
  firstName?: string;
  lastName?: string;
  primary?: boolean;
  emailAddress?: string;
  phoneNumber?: string;
}

export interface LexwareAddress {
  supplement?: string;
  street?: string;
  zip?: string;
  city?: string;
  countryCode?: string;
}

export interface LexwareEmailAddresses {
  business?: string[];
  office?: string[];
  private?: string[];
  other?: string[];
}

export interface LexwarePhoneNumbers {
  business?: string[];
  office?: string[];
  mobile?: string[];
  private?: string[];
  fax?: string[];
  other?: string[];
}

export interface LexwareContactRoles {
  customer?: { number?: number };
  vendor?: { number?: number };
}

export interface LexwareContact {
  id: string;
  organizationId?: string;
  version: number;
  roles: LexwareContactRoles;
  company?: LexwareContactCompany;
  person?: LexwareContactPerson;
  addresses?: {
    billing?: LexwareAddress[];
    shipping?: LexwareAddress[];
  };
  emailAddresses?: LexwareEmailAddresses;
  phoneNumbers?: LexwarePhoneNumbers;
  note?: string;
  archived?: boolean;
}

export interface LexwareContactListResponse {
  content: LexwareContact[];
  first: boolean;
  last: boolean;
  totalPages: number;
  totalElements: number;
  numberOfElements: number;
  size: number;
  number: number;
}

export interface LexwareContactCreateResponse {
  id: string;
  resourceUri: string;
  createdDate: string;
  updatedDate: string;
  version: number;
}

// --------------------------------------------------------
// Voucher / Beleg Interfaces
// --------------------------------------------------------

export interface LexwareVoucherListItem {
  id: string;
  voucherType: string;
  voucherNumber: string;
  voucherDate: string;
  voucherStatus: string;
  totalAmount: number;
  openAmount?: number;
  currency: string;
  contactId?: string;
  contactName?: string;
  dueDate?: string;
  createdDate?: string;
  updatedDate?: string;
  archived?: boolean;
}

export interface LexwareVoucherListResponse {
  content: LexwareVoucherListItem[];
  first: boolean;
  last: boolean;
  totalPages: number;
  totalElements: number;
  size: number;
  number: number;
}

export interface LexwareLineItem {
  id?: string;
  type: string;
  name: string;
  description?: string;
  quantity: number;
  unitName?: string;
  unitPrice?: {
    currency: string;
    netAmount: number;
    grossAmount: number;
    taxRatePercentage: number;
  };
  lineItemAmount?: number;
}

export interface LexwareTotalPrice {
  currency: string;
  totalNetAmount: number;
  totalGrossAmount: number;
  totalTaxAmount: number;
  totalDiscountAbsolute?: number;
  totalDiscountPercentage?: number;
}

export interface LexwareVoucherAddress {
  contactId?: string;
  name?: string;
  supplement?: string;
  street?: string;
  city?: string;
  zip?: string;
  countryCode?: string;
  contactPerson?: string;
}

export interface LexwareVoucherDetail {
  id: string;
  organizationId?: string;
  voucherNumber?: string;
  voucherDate?: string;
  voucherStatus?: string;
  createdDate?: string;
  updatedDate?: string;
  version?: number;
  archived?: boolean;
  language?: string;
  address?: LexwareVoucherAddress;
  lineItems?: LexwareLineItem[];
  totalPrice?: LexwareTotalPrice;
  taxConditions?: {
    taxType?: string;
  };
  title?: string;
  introduction?: string;
  remark?: string;
  relatedVouchers?: Array<{
    id: string;
    voucherNumber: string;
    voucherType: string;
  }>;
}

// Type alias fuer spezifische Voucher-Typen (gleiche Struktur)
export type LexwareInvoiceDetail = LexwareVoucherDetail & {
  paymentConditions?: {
    paymentTermLabel?: string;
    dueDate?: string;
  };
  shippingConditions?: {
    shippingConditionsLabel?: string;
    deliveryTerms?: string;
  };
};

export type LexwareQuotationDetail = LexwareVoucherDetail;
export type LexwareOrderConfirmationDetail = LexwareVoucherDetail;
export type LexwareCreditNoteDetail = LexwareVoucherDetail;

// --------------------------------------------------------
// Event Subscription Interfaces
// --------------------------------------------------------

export interface LexwareEventSubscription {
  subscriptionId: string;
  organizationId: string;
  createdDate: string;
  eventType: string;
  callbackUrl: string;
}
