"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useGetIngests;
const streamplace_1 = require("streamplace");
const streamplace_store_1 = require("./streamplace-store");
const xrpc_1 = require("./xrpc");
function useGetIngests() {
    const pdsAgent = (0, xrpc_1.usePDSAgent)();
    const did = (0, streamplace_store_1.useDID)();
    const setIngests = (0, streamplace_store_1.useStreamplaceStore)((state) => state.setIngests);
    return async () => {
        if (!pdsAgent || !did) {
            throw new Error("No PDS agent or DID available");
        }
        const result = await pdsAgent.place.stream.ingest.getIngestUrls();
        if (!result.success) {
            throw new Error("Failed to get ingests");
        }
        const ingests = result.data.ingests
            .map((ingest) => {
            if (streamplace_1.PlaceStreamIngestDefs.isIngest(ingest)) {
                return ingest;
            }
            console.error("Invalid ingest", ingest);
            return null;
        })
            .filter((ingest) => ingest !== null);
        setIngests(ingests);
    };
}
//# sourceMappingURL=ingest.js.map