import {
	CustomPackageResponse,
	LocationResponse,
	ResponseLabel,
} from './connect-server';
import { StoreOptions } from './store-options';
import { Order } from './order';
import { HazmatState } from './hazmat-state';
import { Continent } from './continent';
import { SelectedRates } from './selected-rates';
import { SelectedOrigin } from './selected-origin';
import { SelectedDestination } from './selected-destination';
import { CustomsState } from './customs-state';
import { Carrier } from './carrier';
import { Constants } from './constants';
import { ShipmentRecord } from './helpers';
import { UserMeta } from './user-meta';
import { PurchaseSettings } from './purchase-settings';
import { PurchaseMeta } from './purchase-meta';
import { ShipmentDate } from './shipment-date';
import { Promotion } from './promotion';
import { PackageDimensions } from './package-dimensions';

export interface WCShippingConfigAccountSettings {
	purchaseSettings: PurchaseSettings;
	purchaseMeta: PurchaseMeta;
	userMeta: UserMeta;
	storeOptions: StoreOptions;
}

// Todo: Gradually improve this type definition.
export interface WCShippingConfig {
	order: Order;
	accountSettings: WCShippingConfigAccountSettings;
	context: string;
	continents: Continent[];
	is_destination_verified: boolean;
	is_origin_verified: boolean;
	items: number;
	packagesSettings: Record< string, unknown > & {
		packages: {
			custom: CustomPackageResponse[];
			predefined: Record< string, string[] >;
		};
		schema: Record< string, unknown >;
	};
	shipments: Record< string, unknown >[];
	shipments_autogenerated_from_labels: int[];
	shippingLabelData: Record< string, unknown > & {
		storeOptions: StoreOptions;
		currentOrderLabels: ResponseLabel[];
		storedData: {
			destination: LocationResponse;
			selected_rates: SelectedRates | '';
			selected_hazmat: HazmatState | '';
			selected_origin: SelectedOrigin | '';
			selected_destination: SelectedDestination | '';
			customs_information: ShipmentRecord< CustomsState > | '';
			shipment_dates: ShipmentRecord< ShipmentDate< string > > | '';
			package_dimensions:
				| ShipmentRecord< Record< number, PackageDimensions > >
				| '';
		};
	};
	origin_addresses: LocationResponse[];
	eu_countries: string[];
	constants: Constants;
	/** @deprecated Kept for backward compatibility. Always returns an empty structure. */
	carrier_strategies: {
		upsdap: {
			origin_address: Record<
				string,
				{
					has_agreed_to_tos: boolean;
				}
			>;
		};
	};
	is_main_origin_in_sync_with_store?: boolean;
	formatted_store_address?: string;
	store_address_draft?: LocationResponse | null;
	custom_fulfillment_summary: string;
	promotion?: Promotion;
	should_use_fulfillment_api: boolean;
	scanFormEnabled?: boolean;
	bulk_labels_enabled?: boolean;
	/**
	 * Maximum number of orders the bulk-labels modal will accept in a
	 * single pass. Sourced from
	 * `OrdersShippingContextRESTController::BATCH_SIZE_CAP` so PHP is
	 * the single source of truth.
	 */
	bulk_labels_max_orders?: number;
	mode?: 'label-purchase' | 'address-editor';
	address?: unknown;
	onAddressComplete?: ( address: unknown ) => void;
	onAddressCancel?: () => void;
}
