fragment BasicChannelFields on Channel {
  id
  title
  createdAt

  avatarPhotoUrls
  avatarPhotoAvailability
  avatarPhotoDataObject {
    ...DataObjectFields
  }
}

fragment AllChannelFields on Channel {
  ...BasicChannelFields
  description
  follows
  views
  isPublic
  isCensored
  language {
    id
    iso
  }
  ownerMember {
    id
    handle
    avatarUri
  }
  coverPhotoUrls
  coverPhotoAvailability
  coverPhotoDataObject {
    ...DataObjectFields
  }
}

query GetBasicChannel($where: ChannelWhereUniqueInput!) {
  channelByUniqueInput(where: $where) {
    ...BasicChannelFields
  }
}

query GetChannel($where: ChannelWhereUniqueInput!) {
  channelByUniqueInput(where: $where) {
    ...AllChannelFields
  }
}

query GetVideoCount($where: VideoWhereInput) {
  videosConnection(first: 0, where: $where) {
    totalCount
  }
}

query GetChannels($offset: Int, $limit: Int, $where: ChannelWhereInput) {
  channels(offset: $offset, limit: $limit, where: $where) {
    ...AllChannelFields
  }
}

query GetChannelsConnection(
  $first: Int
  $after: String
  $where: ChannelWhereInput
  $orderBy: [ChannelOrderByInput!] = [createdAt_DESC]
) {
  channelsConnection(first: $first, after: $after, where: $where, orderBy: $orderBy) {
    edges {
      cursor
      node {
        ...AllChannelFields
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
    totalCount
  }
}

### Orion

# modyfying this query name will need a sync-up in `src/api/client/resolvers.ts`
query GetChannelViews($channelId: ID!) {
  channelViews(channelId: $channelId) {
    id
    views
  }
}

# modyfying this query name will need a sync-up in `src/api/client/resolvers.ts`
query GetChannelFollows($channelId: ID!) {
  channelFollows(channelId: $channelId) {
    id
    follows
  }
}

query GetBatchedChannelFollows($channelIdList: [ID!]!) {
  batchedChannelFollows(channelIdList: $channelIdList) {
    id
    follows
  }
}

query GetBatchedChannelViews($channelIdList: [ID!]!) {
  batchedChannelsViews(channelIdList: $channelIdList) {
    id
    views
  }
}

mutation FollowChannel($channelId: ID!) {
  followChannel(channelId: $channelId) {
    id
    follows
  }
}

mutation UnfollowChannel($channelId: ID!) {
  unfollowChannel(channelId: $channelId) {
    id
    follows
  }
}

query GetMostViewedChannels($viewedWithinDays: Int!, $limit: Int) {
  mostViewedChannels(period: $viewedWithinDays, limit: $limit) {
    id
    views
  }
}

query GetMostViewedChannelsAllTime($limit: Int!) {
  mostViewedChannelsAllTime(limit: $limit) {
    id
    views
  }
}
