import { getSubgraphSdk } from "../utils/graphql";
export async function getBuyerById(subgraphUrl, buyerId, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { buyer } = await sdk.getBuyerByIdQuery({
        buyerId: buyerId.toString(),
        ...queryVars
    });
    return buyer;
}
export async function getBuyers(subgraphUrl, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { buyers = [] } = await sdk.getBuyersQuery(queryVars);
    return buyers;
}
export async function getSellerById(subgraphUrl, sellerId, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { seller } = await sdk.getSellerByIdQuery({
        sellerId: sellerId.toString(),
        ...queryVars
    });
    return seller;
}
export async function getSellers(subgraphUrl, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { sellers = [] } = await sdk.getSellersQuery(queryVars);
    return sellers;
}
export async function getSellerByAssistant(subgraphUrl, assistantAddress, queryVars = {}) {
    const sellers = await getSellers(subgraphUrl, {
        sellersFilter: {
            ...queryVars.sellersFilter,
            assistant: assistantAddress.toLowerCase()
        },
        ...queryVars
    });
    return sellers[0];
}
export async function getSellerByAdmin(subgraphUrl, adminAddress, queryVars = {}) {
    const sellers = await getSellers(subgraphUrl, {
        sellersFilter: {
            ...queryVars.sellersFilter,
            admin: adminAddress.toLowerCase()
        },
        ...queryVars
    });
    return sellers[0];
}
export async function getSellersByTreasury(subgraphUrl, treasuryAddress, queryVars = {}) {
    const sellers = await getSellers(subgraphUrl, {
        sellersFilter: {
            ...queryVars.sellersFilter,
            treasury: treasuryAddress.toLowerCase()
        },
        ...queryVars
    });
    return sellers;
}
export async function getSellerByAuthToken(subgraphUrl, tokenId, tokenType, queryVars = {}) {
    const sellers = await getSellers(subgraphUrl, {
        sellersFilter: {
            ...queryVars.sellersFilter,
            authTokenId: tokenId,
            authTokenType: tokenType
        },
        ...queryVars
    });
    return sellers[0];
}
export async function getSellerByAddress(subgraphUrl, address, queryVars = {}) {
    const [assistant, admin] = await Promise.all([
        getSellerByAssistant(subgraphUrl, address, queryVars),
        getSellerByAdmin(subgraphUrl, address, queryVars)
    ]);
    return assistant || admin;
}
export async function getDisputeResolverById(subgraphUrl, disputeResolverId, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { disputeResolver } = await sdk.getDisputeResolverByIdQuery({
        disputeResolverId: disputeResolverId.toString(),
        ...queryVars
    });
    return disputeResolver;
}
export async function getDisputeResolvers(subgraphUrl, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { disputeResolvers = [] } = await sdk.getDisputeResolversQuery(queryVars);
    return disputeResolvers;
}
export async function getOfferCollections(subgraphUrl, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { offerCollections = [] } = await sdk.getOfferCollectionsQuery(queryVars);
    return offerCollections;
}
export async function getAuthTokenIds(subgraphUrl, queryVars = {}) {
    const sdk = getSubgraphSdk(subgraphUrl);
    const { sellers = [] } = await sdk.getAuthTokenIds(queryVars);
    return sellers;
}
//# sourceMappingURL=subgraph.js.map