"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBuyerById = getBuyerById;
exports.getBuyers = getBuyers;
exports.getSellerById = getSellerById;
exports.getSellers = getSellers;
exports.getSellerByAssistant = getSellerByAssistant;
exports.getSellerByAdmin = getSellerByAdmin;
exports.getSellersByTreasury = getSellersByTreasury;
exports.getSellerByAuthToken = getSellerByAuthToken;
exports.getSellerByAddress = getSellerByAddress;
exports.getDisputeResolverById = getDisputeResolverById;
exports.getDisputeResolvers = getDisputeResolvers;
exports.getOfferCollections = getOfferCollections;
exports.getAuthTokenIds = getAuthTokenIds;
const graphql_1 = require("../utils/graphql");
function getBuyerById(subgraphUrl_1, buyerId_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, buyerId, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { buyer } = yield sdk.getBuyerByIdQuery(Object.assign({ buyerId: buyerId.toString() }, queryVars));
        return buyer;
    });
}
function getBuyers(subgraphUrl_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { buyers = [] } = yield sdk.getBuyersQuery(queryVars);
        return buyers;
    });
}
function getSellerById(subgraphUrl_1, sellerId_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, sellerId, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { seller } = yield sdk.getSellerByIdQuery(Object.assign({ sellerId: sellerId.toString() }, queryVars));
        return seller;
    });
}
function getSellers(subgraphUrl_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { sellers = [] } = yield sdk.getSellersQuery(queryVars);
        return sellers;
    });
}
function getSellerByAssistant(subgraphUrl_1, assistantAddress_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, assistantAddress, queryVars = {}) {
        const sellers = yield getSellers(subgraphUrl, Object.assign({ sellersFilter: Object.assign(Object.assign({}, queryVars.sellersFilter), { assistant: assistantAddress.toLowerCase() }) }, queryVars));
        return sellers[0];
    });
}
function getSellerByAdmin(subgraphUrl_1, adminAddress_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, adminAddress, queryVars = {}) {
        const sellers = yield getSellers(subgraphUrl, Object.assign({ sellersFilter: Object.assign(Object.assign({}, queryVars.sellersFilter), { admin: adminAddress.toLowerCase() }) }, queryVars));
        return sellers[0];
    });
}
function getSellersByTreasury(subgraphUrl_1, treasuryAddress_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, treasuryAddress, queryVars = {}) {
        const sellers = yield getSellers(subgraphUrl, Object.assign({ sellersFilter: Object.assign(Object.assign({}, queryVars.sellersFilter), { treasury: treasuryAddress.toLowerCase() }) }, queryVars));
        return sellers;
    });
}
function getSellerByAuthToken(subgraphUrl_1, tokenId_1, tokenType_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, tokenId, tokenType, queryVars = {}) {
        const sellers = yield getSellers(subgraphUrl, Object.assign({ sellersFilter: Object.assign(Object.assign({}, queryVars.sellersFilter), { authTokenId: tokenId, authTokenType: tokenType }) }, queryVars));
        return sellers[0];
    });
}
function getSellerByAddress(subgraphUrl_1, address_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, address, queryVars = {}) {
        const [assistant, admin] = yield Promise.all([
            getSellerByAssistant(subgraphUrl, address, queryVars),
            getSellerByAdmin(subgraphUrl, address, queryVars)
        ]);
        return assistant || admin;
    });
}
function getDisputeResolverById(subgraphUrl_1, disputeResolverId_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, disputeResolverId, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { disputeResolver } = yield sdk.getDisputeResolverByIdQuery(Object.assign({ disputeResolverId: disputeResolverId.toString() }, queryVars));
        return disputeResolver;
    });
}
function getDisputeResolvers(subgraphUrl_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { disputeResolvers = [] } = yield sdk.getDisputeResolversQuery(queryVars);
        return disputeResolvers;
    });
}
function getOfferCollections(subgraphUrl_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { offerCollections = [] } = yield sdk.getOfferCollectionsQuery(queryVars);
        return offerCollections;
    });
}
function getAuthTokenIds(subgraphUrl_1) {
    return __awaiter(this, arguments, void 0, function* (subgraphUrl, queryVars = {}) {
        const sdk = (0, graphql_1.getSubgraphSdk)(subgraphUrl);
        const { sellers = [] } = yield sdk.getAuthTokenIds(queryVars);
        return sellers;
    });
}
//# sourceMappingURL=subgraph.js.map