export interface WooCommerceOrder {
	id: number;
	parent_id: number;
	status: OrderStatus;
	currency: string;
	version: string;
	prices_include_tax: boolean;
	date_created: string;
	date_modified: string;
	discount_total: string;
	discount_tax: string;
	shipping_total: string;
	shipping_tax: string;
	cart_tax: string;
	total: string;
	total_tax: string;
	customer_id: number;
	order_key: string;
	billing: BillingAddress;
	shipping: ShippingAddress;
	payment_method: string;
	payment_method_title: string;
	transaction_id: string;
	customer_ip_address: string;
	customer_user_agent: string;
	created_via: string;
	customer_note: string;
	date_completed: string | null;
	date_paid: string | null;
	cart_hash: string;
	number: string;
	meta_data: MetaDataItem[];
	line_items: LineItem[];
	tax_lines: TaxLine[];
	shipping_lines: ShippingLine[];
	fee_lines: FeeLine[];
	coupon_lines: CouponLine[];
	refunds: Refund[];
	payment_url: string;
	is_editable: boolean;
	needs_payment: boolean;
	needs_processing: boolean;
	date_created_gmt: string;
	date_modified_gmt: string;
	date_completed_gmt: string | null;
	date_paid_gmt: string | null;
	currency_symbol: string;
	_links: OrderLinks;
}

export type OrderStatus =
	| 'pending'
	| 'processing'
	| 'on-hold'
	| 'completed'
	| 'cancelled'
	| 'refunded'
	| 'failed'
	| 'trash';

export interface BillingAddress {
	first_name: string;
	last_name: string;
	company: string;
	address_1: string;
	address_2: string;
	city: string;
	state: string;
	postcode: string;
	country: string;
	email: string;
	phone: string;
}

export interface ShippingAddress {
	first_name: string;
	last_name: string;
	company: string;
	address_1: string;
	address_2: string;
	city: string;
	state: string;
	postcode: string;
	country: string;
	phone: string;
}

export interface MetaDataItem {
	id: number;
	key: string;
	value: string | number | boolean | object;
}

export interface LineItem {
	id: number;
	name: string;
	product_id: number;
	variation_id: number;
	quantity: number;
	tax_class: string;
	subtotal: string;
	subtotal_tax: string;
	total: string;
	total_tax: string;
	taxes: Tax[];
	meta_data: MetaDataItem[];
	sku: string;
	price: number;
	image: ProductImage;
	parent_name?: string;
}

export interface Tax {
	id: number;
	total: string;
	subtotal: string;
}

export interface ProductImage {
	id: number;
	src: string;
}

export interface TaxLine {
	id: number;
	rate_code: string;
	rate_id: number;
	label: string;
	compound: boolean;
	tax_total: string;
	shipping_tax_total: string;
	rate_percent: number;
	meta_data: MetaDataItem[];
}

export interface ShippingLine {
	id: number;
	method_title: string;
	method_id: string;
	instance_id: string;
	total: string;
	total_tax: string;
	taxes: Tax[];
	meta_data: MetaDataItem[];
}

export interface FeeLine {
	id: number;
	name: string;
	tax_class: string;
	tax_status: string;
	total: string;
	total_tax: string;
	taxes: Tax[];
	meta_data: MetaDataItem[];
}

export interface CouponLine {
	id: number;
	code: string;
	discount: string;
	discount_tax: string;
	meta_data: MetaDataItem[];
}

export interface Refund {
	id: number;
	reason: string;
	total: string;
}

export interface OrderLinks {
	self: Link[];
	collection: Link[];
	email_templates?: Link[];
}

export interface Link {
	href: string;
	embeddable?: boolean;
	targetHints?: {
		allow: string[];
	};
}

export type CreateOrderData = Omit<
	WooCommerceOrder,
	| 'id'
	| 'date_created'
	| 'date_modified'
	| 'date_created_gmt'
	| 'date_modified_gmt'
	| 'order_key'
	| 'number'
	| 'payment_url'
	| '_links'
>;

export type UpdateOrderData = Partial<
	Omit<WooCommerceOrder, 'id' | 'date_created' | 'date_created_gmt' | '_links'>
>;
