// Wave types (duplicated from page.server.ts since we can't import from there)
export interface WaveAddress {
	addressLine1: string | null;
	addressLine2: string | null;
	city: string | null;
	province: { code: string; name: string } | null;
	country: { code: string; name: string } | null;
	postalCode: string | null;
}

export interface WaveCustomer {
	id: string;
	name: string;
	firstName: string | null;
	lastName: string | null;
	email: string | null;
	phone: string | null;
	mobile: string | null;
	address: WaveAddress | null;
	currency: { code: string; symbol: string } | null;
	internalNotes: string | null;
	outstandingAmount: { value: string; currency: { code: string } };
	overdueAmount: { value: string; currency: { code: string } };
	isArchived: boolean | null;
	createdAt: string;
	modifiedAt: string;
}

// Base WaveProduct with required fields - used across all pages
export interface WaveProduct {
	id: string;
	name: string;
	description: string | null;
	unitPrice: number;
	isArchived: boolean;
	// Optional extended fields - available on Wave admin page
	isSold?: boolean;
	isBought?: boolean;
	incomeAccount?: { id: string; name: string } | null;
	expenseAccount?: { id: string; name: string } | null;
	defaultSalesTaxes?: Array<{ id: string; name: string; abbreviation: string }>;
	createdAt?: string;
	modifiedAt?: string;
}

export interface WaveInvoiceItem {
	product: { id: string; name: string };
	description: string | null;
	quantity: number;
	unitPrice: number;
	subtotal: { value: string };
	total: { value: string };
}

export interface WaveInvoice {
	id: string;
	invoiceNumber: string;
	invoiceDate: string;
	dueDate: string;
	status: string;
	title: string;
	subhead: string | null;
	poNumber: string | null;
	memo: string | null;
	footer: string | null;
	pdfUrl: string;
	viewUrl: string;
	customer: { id: string; name: string; email: string | null };
	items: WaveInvoiceItem[];
	subtotal: { value: string; currency: { code: string; symbol: string } };
	taxTotal: { value: string; currency: { code: string; symbol: string } };
	discountTotal: { value: string; currency: { code: string; symbol: string } };
	total: { value: string; currency: { code: string; symbol: string } };
	amountDue: { value: string; currency: { code: string; symbol: string } };
	amountPaid: { value: string; currency: { code: string; symbol: string } };
	lastSentAt: string | null;
	lastSentVia: string | null;
	lastViewedAt: string | null;
}

// Types for revenue and project data from Nexus invoice
export interface NexusRevenue {
	id: string;
	accountId: string;
	amount: string | number;
	startDate: string;
	endDate: string | null;
	waveServiceId: string | null;
}

export interface NexusProject {
	id: string;
	name: string;
	date: string;
	amount: string | number;
	customerId: string;
	accountAddressId: string | null;
	waveServiceId: string | null;
}

export interface NexusInvoice {
	id: string;
	date: string;
	customerId: string;
	status: string;
	datePaid: string | null;
	paymentType: string | null;
	waveInvoiceId: string | null;
	revenues: NexusRevenue[];
	projects: NexusProject[];
}

// Types for the invoice form
export interface WaveLineItem {
	sourceType: 'revenue' | 'project' | 'additional';
	sourceId: string;
	productId: string;
	productName: string;
	description: string;
	quantity: number;
	unitPrice: number;
}

export interface WaveDiscount {
	type: 'PERCENTAGE' | 'FIXED';
	name: string;
	value: number; // percentage (0-100) or fixed amount
}

export interface WaveInvoiceFormData {
	invoiceDate: string;
	dueDate: string;
	memo: string;
	footer: string;
	items: WaveLineItem[];
	discount?: WaveDiscount;
}

// Validation types
export interface ValidationIssue {
	type: 'customer' | 'revenue' | 'project';
	id: string;
	description: string;
}

export type InvoiceTab = 'details' | 'wave';
