# CHANGE: Dropped because unused:
# query GetBasicChannel(...) { ... }

query GetFullChannel($id: String!) {
  # CHANGE: `channelByUniqueInput` is no longer supported in subsquid, replaced with `channelById`
  channelById(id: $id) {
    ...FullChannelFields
  }
}

# CHANGE: `channels` replaced with `extendedChannels` (which include `activeVideosCount`)
query GetExtendedBasicChannels(
  $where: ExtendedChannelWhereInput
  $limit: Int = 50
  $orderBy: [ChannelOrderByInput!] = [createdAt_DESC]
) {
  extendedChannels(where: $where, orderBy: $orderBy, limit: $limit) {
    ...ExtendedBasicChannelFields
  }
}

# CHANGE: `channels` replaced with `extendedChannels` (which include `activeVideosCount`)
query GetExtendedFullChannels(
  $where: ExtendedChannelWhereInput
  $limit: Int = 50
  $orderBy: [ChannelOrderByInput!] = [createdAt_DESC]
) {
  extendedChannels(where: $where, orderBy: $orderBy, limit: $limit) {
    ...ExtendedFullChannelFields
  }
}

# No changes (UNLESS `activeVideosCount` is needed in "where")
query GetBasicChannelsConnection(
  $first: Int
  $after: String
  $where: ChannelWhereInput
  $orderBy: [ChannelOrderByInput!] = [createdAt_DESC]
) {
  channelsConnection(first: $first, after: $after, where: $where, orderBy: $orderBy) {
    edges {
      cursor
      node {
        ...BasicChannelFields
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
    totalCount
  }
}

# CHANGE: `ID` is now `String`
mutation FollowChannel($channelId: String!) {
  followChannel(channelId: $channelId) {
    channelId
    follows
    cancelToken
  }
}

# CHANGE: `ID` is now `String`
mutation UnfollowChannel($channelId: String!, $token: String!) {
  unfollowChannel(channelId: $channelId, token: $token) {
    channelId
    follows
  }
}

# CHANGE: Removed because unused:
# query GetMostViewedChannelsConnection(...) { ... }

query GetTop10Channels($where: ExtendedChannelWhereInput) {
  # CHANGE: Replacement for overly-specific `top10Channels` query
  extendedChannels(where: $where, orderBy: followsNum_DESC, limit: 10) {
    channel {
      ...BasicChannelFields
    }
  }
}

query GetPromisingChannels($where: ExtendedChannelWhereInput) {
  # CHANGE: Replacement for overly-specific `promisingChannels` query
  mostRecentChannels(where: $where, orderBy: videoViewsNum_DESC, mostRecentLimit: 100, resultsLimit: 15) {
    channel {
      ...BasicChannelFields
    }
  }
}

query GetDiscoverChannels($where: ExtendedChannelWhereInput) {
  # CHANGE: Replacement for overly-specific `discoverChannels` query
  mostRecentChannels(where: $where, orderBy: followsNum_DESC, mostRecentLimit: 100, resultsLimit: 15) {
    channel {
      ...BasicChannelFields
    }
  }
}

query GetPopularChannels($where: ExtendedChannelWhereInput) {
  # CHANGE: Replacement for overly-specific `popularChannels` query
  extendedChannels(where: $where, orderBy: videoViewsNum_DESC, limit: 15) {
    channel {
      ...BasicChannelFields
    }
  }
}

# CHANGE: Replaced with a custom `channelNftCollectors` query taking `channelId` argument (instead of `ChannelNftCollectorsWhereInput`)
query GetChannelNftCollectors($channelId: String!, $orderBy: ChannelNftCollectorsOrderByInput = amount_DESC) {
  channelNftCollectors(channelId: $channelId, orderBy: $orderBy) {
    member {
      ...BasicMembershipFields
    }
    amount
  }
}

query GetTotalChannelsAndTotalVideos($memberId: String!, $channelId: String!) {
  membershipById(id: $memberId) {
    totalChannelsCreated
    channels(where: { id_eq: $channelId }) {
      totalVideosCreated
    }
  }
}

# CHANGE: `ID` is now `String`
mutation ReportChannel($channelId: String!, $rationale: String!) {
  reportChannel(channelId: $channelId, rationale: $rationale) {
    id
    channelId
  }
}

# todo needs to be rewritten in orion v2 once payments table is back
query GetChannelPaymentEvents {
  # nftBoughtEvents(where: { ownerMember: { id_eq: $ownerMemberId } }) {
  #   inBlock
  #   createdAt
  #   price
  # }

  # bidMadeCompletingAuctionEvents(where: { ownerMember: { id_eq: $ownerMemberId } }) {
  #   inBlock
  #   createdAt
  #   price
  # }

  # englishAuctionSettledEvents(where: { ownerMember: { id_eq: $ownerMemberId } }) {
  #   createdAt
  #   inBlock
  #   winningBid {
  #     amount
  #   }
  # }

  # openAuctionBidAcceptedEvents(where: { ownerMember: { id_eq: $ownerMemberId } }) {
  #   inBlock
  #   createdAt
  #   winningBid {
  #     amount
  #   }
  # }

  events(
    where: {
      data: {
        isTypeOf_in: [
          "NftBoughtEventData"
          "BidMadeCompletingAuctionEventData"
          "EnglishAuctionSettledEventData"
          "OpenAuctionBidAcceptedEventData"
        ]
      }
    }
  ) {
    id
    timestamp
    inBlock
    data {
      __typename
      ... on NftBoughtEventData {
        price
      }
      ... on BidMadeCompletingAuctionEventData {
        winningBid {
          id
          amount
        }
      }
      ... on EnglishAuctionSettledEventData {
        winningBid {
          amount
        }
      }
      ... on OpenAuctionBidAcceptedEventData {
        winningBid {
          amount
        }
      }
    }
  }

  #  channelRewardClaimedEvents(where: { channel: { id_eq: $channelId } }) {
  #    amount
  #    createdAt
  #    inBlock
  #  }

  #  channelFundsWithdrawnEvents(where: { channel: { id_eq: $channelId } }) {
  #    amount
  #    createdAt
  #    inBlock
  #  }
}
