"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tickerExternalAgentActions = exports.tickerExternalAgentHistory = exports.getHistoryOfPaymentEventsForCa = exports.getWithholdingTaxesOfCa = exports.investments = exports.settlements = exports.eventByAddedTrustedClaimIssuer = exports.heartbeat = exports.latestProcessedBlock = exports.proposal = exports.issuerDidsWithClaimsByTarget = exports.scopesByIdentity = exports.transactions = exports.tokensHeldByDid = exports.tokensByTrustedClaimIssuer = exports.proposals = exports.transactionByHash = exports.eventsByIndexedArgs = exports.eventByIndexedArgs = exports.didsWithClaims = exports.proposalVotes = void 0;
const graphql_tag_1 = __importDefault(require("graphql-tag"));
/**
 * @hidden
 *
 * Get the current voters list for given pipId
 */
function proposalVotes(variables) {
    const query = (0, graphql_tag_1.default) `
    query ProposalVotesQuery(
      $pipId: Int!
      $vote: Boolean!
      $count: Int
      $skip: Int
      $orderBy: ProposalVotesOrderByInput
    ) {
      proposalVotes(pipId: $pipId, vote: $vote, count: $count, skip: $skip, orderBy: $orderBy) {
        blockId
        eventIdx
        account
        vote
        weight
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.proposalVotes = proposalVotes;
/**
 * @hidden
 *
 * Get all dids with at least one claim for a given scope and from one the given trustedClaimIssuers
 */
function didsWithClaims(variables) {
    const query = (0, graphql_tag_1.default) `
    query DidsWithClaimsQuery(
      $dids: [String!]
      $scope: ScopeInput
      $trustedClaimIssuers: [String!]
      $claimTypes: [ClaimTypeEnum!]
      $includeExpired: Boolean
      $count: Int
      $skip: Int
    ) {
      didsWithClaims(
        dids: $dids
        scope: $scope
        trustedClaimIssuers: $trustedClaimIssuers
        claimTypes: $claimTypes
        includeExpired: $includeExpired
        count: $count
        skip: $skip
      ) {
        totalCount
        items {
          did
          claims {
            targetDID
            issuer
            issuance_date
            last_update_date
            expiry
            type
            jurisdiction
            cdd_id
            scope {
              type
              value
            }
          }
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.didsWithClaims = didsWithClaims;
/**
 * @hidden
 *
 * Get a single event by any of its indexed arguments
 */
function eventByIndexedArgs(variables) {
    const query = (0, graphql_tag_1.default) `
    query EventByIndexedArgsQuery(
      $moduleId: ModuleIdEnum!
      $eventId: EventIdEnum!
      $eventArg0: String
      $eventArg1: String
      $eventArg2: String
    ) {
      eventByIndexedArgs(
        moduleId: $moduleId
        eventId: $eventId
        eventArg0: $eventArg0
        eventArg1: $eventArg1
        eventArg2: $eventArg2
      ) {
        block_id
        event_idx
        extrinsic_idx
        block {
          datetime
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.eventByIndexedArgs = eventByIndexedArgs;
/**
 * @hidden
 *
 * Get all events by any of its indexed arguments
 */
function eventsByIndexedArgs(variables) {
    const query = (0, graphql_tag_1.default) `
    query EventsByIndexedArgsQuery(
      $moduleId: ModuleIdEnum!
      $eventId: EventIdEnum!
      $eventArg0: String
      $eventArg1: String
      $eventArg2: String
      $count: Int
      $skip: Int
    ) {
      eventsByIndexedArgs(
        moduleId: $moduleId
        eventId: $eventId
        eventArg0: $eventArg0
        eventArg1: $eventArg1
        eventArg2: $eventArg2
        count: $count
        skip: $skip
      ) {
        block_id
        event_idx
        extrinsic_idx
        block {
          datetime
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.eventsByIndexedArgs = eventsByIndexedArgs;
/**
 * @hidden
 *
 * Get a transaction by hash
 */
function transactionByHash(variables) {
    const query = (0, graphql_tag_1.default) `
    query TransactionByHashQuery($transactionHash: String) {
      transactionByHash(transactionHash: $transactionHash) {
        block_id
        extrinsic_idx
        address
        nonce
        module_id
        call_id
        params
        success
        spec_version_id
        extrinsic_hash
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.transactionByHash = transactionByHash;
/**
 * @hidden
 *
 * Get all proposals optionally filtered by pipId, proposer or state
 */
function proposals(variables) {
    const query = (0, graphql_tag_1.default) `
    query ProposalsQuery(
      $pipIds: [Int!]
      $proposers: [String!]
      $states: [ProposalState!]
      $count: Int
      $skip: Int
      $orderBy: ProposalOrderByInput
    ) {
      proposals(
        pipIds: $pipIds
        proposers: $proposers
        states: $states
        count: $count
        skip: $skip
        orderBy: $orderBy
      ) {
        pipId
        proposer
        createdAt
        url
        description
        coolOffEndBlock
        endBlock
        proposal
        lastState
        lastStateUpdatedAt
        totalVotes
        totalAyesWeight
        totalNaysWeight
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.proposals = proposals;
/**
 * @hidden
 *
 * Get the tickers of all the Assets for which the passed DID is a trusted claim issuer
 */
function tokensByTrustedClaimIssuer(variables) {
    const query = (0, graphql_tag_1.default) `
    query TokensByTrustedClaimIssuerQuery($claimIssuerDid: String!) {
      tokensByTrustedClaimIssuer(claimIssuerDid: $claimIssuerDid)
    }
  `;
    return {
        query,
        variables,
    };
}
exports.tokensByTrustedClaimIssuer = tokensByTrustedClaimIssuer;
/**
 * @hidden
 *
 * Get all tickers of Assets that were held at some point by the given did
 */
function tokensHeldByDid(variables) {
    const query = (0, graphql_tag_1.default) `
    query TokensHeldByDidQuery($did: String!, $count: Int, $skip: Int, $order: Order) {
      tokensHeldByDid(did: $did, count: $count, skip: $skip, order: $order) {
        totalCount
        items
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.tokensHeldByDid = tokensHeldByDid;
/**
 * @hidden
 *
 * Get transactions
 */
function transactions(variables) {
    const query = (0, graphql_tag_1.default) `
    query TransactionsQuery(
      $block_id: Int
      $address: String
      $module_id: ModuleIdEnum
      $call_id: CallIdEnum
      $success: Boolean
      $count: Int
      $skip: Int
      $orderBy: TransactionOrderByInput
    ) {
      transactions(
        block_id: $block_id
        address: $address
        module_id: $module_id
        call_id: $call_id
        success: $success
        count: $count
        skip: $skip
        orderBy: $orderBy
      ) {
        totalCount
        items {
          block_id
          extrinsic_idx
          address
          nonce
          module_id
          call_id
          params
          success
          spec_version_id
          extrinsic_hash
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.transactions = transactions;
/**
 * @hidden
 *
 * Get the scopes (and ticker, if applicable) of claims issued on an Identity
 */
function scopesByIdentity(variables) {
    const query = (0, graphql_tag_1.default) `
    query ScopesByIdentityQuery($did: String!) {
      scopesByIdentity(did: $did) {
        scope {
          type
          value
        }
        ticker
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.scopesByIdentity = scopesByIdentity;
/**
 * @hidden
 *
 * Get issuer dids with at least one claim for given target
 */
function issuerDidsWithClaimsByTarget(variables) {
    const query = (0, graphql_tag_1.default) `
    query IssuerDidsWithClaimsByTargetQuery(
      $target: String!
      $scope: ScopeInput
      $trustedClaimIssuers: [String!]
      $includeExpired: Boolean
      $count: Int
      $skip: Int
    ) {
      issuerDidsWithClaimsByTarget(
        target: $target
        scope: $scope
        trustedClaimIssuers: $trustedClaimIssuers
        includeExpired: $includeExpired
        count: $count
        skip: $skip
      ) {
        totalCount
        items {
          did
          claims {
            targetDID
            issuer
            issuance_date
            last_update_date
            expiry
            type
            jurisdiction
            cdd_id
            scope {
              type
              value
            }
          }
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.issuerDidsWithClaimsByTarget = issuerDidsWithClaimsByTarget;
/**
 * @hidden
 *
 * Get a proposal by its pipId
 */
function proposal(variables) {
    const query = (0, graphql_tag_1.default) `
    query ProposalQuery($pipId: Int!) {
      proposal(pipId: $pipId) {
        pipId
        proposer
        createdAt
        url
        description
        coolOffEndBlock
        endBlock
        proposal
        lastState
        lastStateUpdatedAt
        totalVotes
        totalAyesWeight
        totalNaysWeight
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.proposal = proposal;
/**
 * @hidden
 *
 * Fetch the number of the latest block that has been processed by the middleware
 */
function latestProcessedBlock() {
    const query = (0, graphql_tag_1.default) `
    query {
      latestBlock {
        id
      }
    }
  `;
    return {
        query,
        variables: undefined,
    };
}
exports.latestProcessedBlock = latestProcessedBlock;
/**
 * @hidden
 *
 * Middleware heartbeat
 */
function heartbeat() {
    const query = (0, graphql_tag_1.default) `
    query {
      heartbeat
    }
  `;
    return {
        query,
        variables: undefined,
    };
}
exports.heartbeat = heartbeat;
/**
 * @hidden
 *
 * Get an added trusted claim issuer event by its indexed arguments
 */
function eventByAddedTrustedClaimIssuer(variables) {
    const query = (0, graphql_tag_1.default) `
    query EventByAddedTrustedClaimIssuerQuery($ticker: String!, $identityId: String!) {
      eventByAddedTrustedClaimIssuer(ticker: $ticker, identityId: $identityId) {
        block_id
        event_idx
        extrinsic_idx
        block {
          datetime
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.eventByAddedTrustedClaimIssuer = eventByAddedTrustedClaimIssuer;
/**
 * @hidden
 *
 * Get Settlements where a Portfolio is involved
 */
function settlements(variables) {
    const query = (0, graphql_tag_1.default) `
    query SettlementsQuery(
      $identityId: String!
      $portfolioNumber: String
      $addressFilter: String
      $tickerFilter: String
      $count: Int
      $skip: Int
    ) {
      settlements(
        identityId: $identityId
        portfolioNumber: $portfolioNumber
        addressFilter: $addressFilter
        tickerFilter: $tickerFilter
        count: $count
        skip: $skip
      ) {
        totalCount
        items {
          block_id
          result
          addresses
          legs {
            ticker
            amount
            direction
            from {
              did
              kind
            }
            to {
              did
              kind
            }
          }
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.settlements = settlements;
/**
 * @hidden
 *
 * Get all investments for a given offering
 */
function investments(variables) {
    const query = (0, graphql_tag_1.default) `
    query InvestmentsQuery($stoId: Int!, $ticker: String!, $count: Int, $skip: Int) {
      investments(stoId: $stoId, ticker: $ticker, count: $count, skip: $skip) {
        totalCount
        items {
          investor
          offeringTokenAmount
          raiseTokenAmount
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.investments = investments;
/**
 * @hidden
 *
 * Get current amount of withheld tax for a distribution
 */
function getWithholdingTaxesOfCa(variables) {
    const query = (0, graphql_tag_1.default) `
    query GetWithholdingTaxesOfCAQuery($CAId: CAId!, $fromDate: DateTime, $toDate: DateTime) {
      getWithholdingTaxesOfCA(CAId: $CAId, fromDate: $fromDate, toDate: $toDate) {
        taxes
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.getWithholdingTaxesOfCa = getWithholdingTaxesOfCa;
/**
 * @hidden
 *
 * Get history of claims for a distribution
 */
function getHistoryOfPaymentEventsForCa(variables) {
    const query = (0, graphql_tag_1.default) `
    query GetHistoryOfPaymentEventsForCAQuery(
      $CAId: CAId!
      $fromDate: DateTime
      $toDate: DateTime
      $count: Int
      $skip: Int
    ) {
      getHistoryOfPaymentEventsForCA(
        CAId: $CAId
        fromDate: $fromDate
        toDate: $toDate
        count: $count
        skip: $skip
      ) {
        totalCount
        items {
          blockId
          eventId
          eventDid
          datetime
          ticker
          localId
          balance
          tax
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.getHistoryOfPaymentEventsForCa = getHistoryOfPaymentEventsForCa;
/**
 * @hidden
 *
 * Get the transaction history of each external agent of an Asset
 */
function tickerExternalAgentHistory(variables) {
    const query = (0, graphql_tag_1.default) `
    query TickerExternalAgentHistoryQuery($ticker: String!) {
      tickerExternalAgentHistory(ticker: $ticker) {
        did
        history {
          datetime
          block_id
          event_idx
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.tickerExternalAgentHistory = tickerExternalAgentHistory;
/**
 * @hidden
 *
 * Get list of Events triggered by actions (from the set of actions that can only be performed by external agents) that have been performed on a specific Asset
 */
function tickerExternalAgentActions(variables) {
    const query = (0, graphql_tag_1.default) `
    query TickerExternalAgentActionsQuery(
      $ticker: String!
      $caller_did: String
      $pallet_name: ModuleIdEnum
      $event_id: EventIdEnum
      $max_block: Int
      $count: Int
      $skip: Int
      $order: Order
    ) {
      tickerExternalAgentActions(
        ticker: $ticker
        caller_did: $caller_did
        pallet_name: $pallet_name
        event_id: $event_id
        max_block: $max_block
        count: $count
        skip: $skip
        order: $order
      ) {
        totalCount
        items {
          datetime
          block_id
          event_idx
          pallet_name
          event_id
          caller_did
        }
      }
    }
  `;
    return {
        query,
        variables,
    };
}
exports.tickerExternalAgentActions = tickerExternalAgentActions;
//# sourceMappingURL=queries.js.map