import * as react from 'react';
import { ReactNode } from 'react';
import { OrderListFilter, Page, Order } from '@platform-modules/commerce-orders';
import { ProductInput, Product } from '@platform-modules/commerce-catalog';
import { ProductPatch, Vendor } from '@platform-modules/commerce-marketplace';
export { isCommissionRateError, isVendorAlreadyExistsError, isVendorAuthorizationError, isVendorNotFoundError, isVendorProductNotFoundError, isVendorStateError } from '@platform-modules/commerce-marketplace';
export { reviveOrderPage } from '@platform-modules/commerce-orders-react';
export { reviveProduct } from '@platform-modules/commerce-catalog-react';

/**
 * Injected, DB-free data seam for browser-side marketplace operations.
 * Host wires each method to an API route that derives the actor from the
 * authenticated session — vendorId NEVER appears as a client param (§1.1 IDOR floor).
 */
interface MarketplaceClient {
    /** Returns wire Vendor | null. null = no vendor yet (host catches VendorNotFoundError → null). */
    getVendorProfile(): Promise<unknown>;
    /** Vendor-scoped order list. Host derives vendorId from session (§1.1). */
    getVendorOrders(filter?: OrderListFilter): Promise<unknown>;
    /** Apply as vendor. Host derives ownerUserId from session. */
    applyAsVendor(input: ApplyAsVendorWire): Promise<unknown>;
    /** Create product. Host derives vendorId from session; strips client-supplied id (§1.2). */
    createVendorProduct(input: CreateVendorProductWire): Promise<unknown>;
    /** Update product. Host verifies product.vendorId === actor's vendor (§1.2). */
    updateVendorProduct(productId: string, patch: ProductPatch): Promise<unknown>;
}
/** Vendor application wire input — NO ownerUserId (derived from session by host). */
interface ApplyAsVendorWire {
    name: string;
}
/** Product create wire input — NO id (server-minted), NO vendorId (§1.2 IDOR floor). */
type CreateVendorProductWire = Omit<ProductInput, 'id' | 'vendorId'>;

interface MarketplaceContextValue {
    client: MarketplaceClient;
}
declare function MarketplaceProvider({ client, children }: {
    client: MarketplaceClient;
    children: ReactNode;
}): react.JSX.Element;

/** Thrown when a marketplace hook is used outside <MarketplaceProvider>. */
declare class MarketplaceProviderError extends Error {
    readonly name = "MarketplaceProviderError";
    constructor(hook: string);
}
declare function isMarketplaceProviderError(e: unknown): e is MarketplaceProviderError;
/** Thrown by reviveVendor / reviveOptionalVendor on malformed wire input. */
declare class MarketplaceWireError extends Error {
    readonly name = "MarketplaceWireError";
    constructor(message: string);
}
declare function isMarketplaceWireError(e: unknown): e is MarketplaceWireError;

declare function reviveVendor(v: unknown): Vendor;
declare function reviveOptionalVendor(v: unknown): Vendor | null;

interface AsyncResource<T> {
    data: T | null;
    loading: boolean;
    error: Error | null;
    reload: () => void;
}

type OptimisticVendor = Omit<Vendor, 'id' | 'createdAt' | 'updatedAt' | 'ownerUserId'> & {
    id: null;
    ownerUserId: string | null;
    createdAt: null;
    updatedAt: null;
};
declare function useApplyAsVendor(): {
    apply: (input: ApplyAsVendorWire) => Promise<Vendor>;
    pending: boolean;
    optimistic: OptimisticVendor | undefined;
    result: Vendor | undefined;
    error: Error | undefined;
    reset: () => void;
};

declare function useCreateVendorProduct(): {
    create: (input: CreateVendorProductWire) => Promise<Product>;
    pending: boolean;
    result: Product | undefined;
    error: Error | undefined;
    reset: () => void;
};

declare function useUpdateVendorProduct(): {
    update: (productId: string, patch: ProductPatch) => Promise<Product>;
    pending: boolean;
    result: Product | undefined;
    error: Error | undefined;
    reset: () => void;
};

declare function useVendorOrders(filter?: OrderListFilter, seed?: {
    initialData?: Page<Order>;
}): {
    page: Page<Order> | null;
    loading: boolean;
    error: Error | null;
    reload: () => void;
};

declare function useVendorProfile(seed?: {
    initialData?: Vendor | null;
}): {
    vendor: Vendor | null;
    loading: boolean;
    error: Error | null;
    reload: () => void;
};

export { type ApplyAsVendorWire, type AsyncResource, type CreateVendorProductWire, type MarketplaceClient, type MarketplaceContextValue, MarketplaceProvider, MarketplaceProviderError, MarketplaceWireError, type OptimisticVendor, isMarketplaceProviderError, isMarketplaceWireError, reviveOptionalVendor, reviveVendor, useApplyAsVendor, useCreateVendorProduct, useUpdateVendorProduct, useVendorOrders, useVendorProfile };
