import { gql } from '@apollo/client/core';

// Experimental queries to discover hidden API endpoints
// Based on patterns: whoLikesMe, whoPingsMe -> try whoILiked, whoIPinged, myLikes, etc.

export const LIKES_PROFILE_FRAGMENT = gql`
  fragment LikesProfileFragment on Profile {
    id
    age
    gender
    status
    lastSeen
    desires
    connectionGoals
    isUplift
    sexuality
    isMajestic
    dateOfBirth
    streamUserId
    imaginaryName
    bio
    hiddenBio
    hasHiddenBio
    allowPWM
    interests
    verificationStatus
    interactionStatus {
      message
      mine
      theirs
      __typename
    }
    distance {
      km
      mi
      __typename
    }
    photos {
      id
      pictureIsPrivate
      pictureIsSafe
      pictureStatus
      pictureType
      pictureUrl
      pictureUrls {
        small
        medium
        large
        __typename
      }
      publicId
      __typename
    }
    __typename
  }
`;

// Attempt 1: whoILiked (mirror of whoLikesMe)
export const WHO_I_LIKED_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query WhoILiked($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: whoILiked(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 2: myLikes
export const MY_LIKES_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query MyLikes($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: myLikes(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 3: sentLikes
export const SENT_LIKES_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query SentLikes($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: sentLikes(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 4: likedProfiles
export const LIKED_PROFILES_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query LikedProfiles($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: likedProfiles(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 5: profilesILiked
export const PROFILES_I_LIKED_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query ProfilesILiked($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: profilesILiked(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 6: outgoingLikes (opposite of incoming likes)
export const OUTGOING_LIKES_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query OutgoingLikes($limit: Int, $cursor: String, $sortBy: SortBy!) {
    interactions: outgoingLikes(
      input: {sortBy: $sortBy}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 7: Try interactions query with direction parameter
export const INTERACTIONS_OUTGOING_QUERY = gql`
  ${LIKES_PROFILE_FRAGMENT}
  query InteractionsOutgoing($limit: Int, $cursor: String, $sortBy: SortBy!, $direction: String) {
    interactions(
      input: {sortBy: $sortBy, direction: $direction}
      limit: $limit
      cursor: $cursor
    ) {
      nodes {
        ...LikesProfileFragment
        __typename
      }
      pageInfo {
        total
        hasNextPage
        nextPageCursor
        __typename
      }
      __typename
    }
  }
`;

// Attempt 8: Try whoLikesMe with a filter for mine=LIKED
export const FILTERED_WHO_I_LIKED_MUTATION = gql`
  ${LIKES_PROFILE_FRAGMENT}
  mutation FilteredWhoILiked($input: FilteredInteractionInput!, $cursor: String) {
    filteredWhoILiked(input: $input, cursor: $cursor) {
      filters {
        ageRange
        desires
        lookingFor
        sexualities
        __typename
      }
      profiles {
        nodes {
          ...LikesProfileFragment
          __typename
        }
        pageInfo {
          total
          unfilteredTotal
          hasNextPage
          nextPageCursor
          __typename
        }
        __typename
      }
      __typename
    }
  }
`;

// Direct profile lookup query - to test if profile IDs from WhoLikesMe return real data
export const DIRECT_PROFILE_LOOKUP_QUERY = gql`
  query DirectProfileLookup($profileId: String!) {
    profile(id: $profileId) {
      id
      age
      gender
      sexuality
      imaginaryName
      bio
      desires
      connectionGoals
      verificationStatus
      distance {
        km
        mi
        __typename
      }
      photos {
        id
        pictureUrl
        pictureUrls {
          small
          medium
          large
          __typename
        }
        publicId
        __typename
      }
      __typename
    }
  }
`;

// List of all experimental queries to try
export const EXPERIMENTAL_QUERIES = [
  { name: 'whoILiked', query: WHO_I_LIKED_QUERY },
  { name: 'myLikes', query: MY_LIKES_QUERY },
  { name: 'sentLikes', query: SENT_LIKES_QUERY },
  { name: 'likedProfiles', query: LIKED_PROFILES_QUERY },
  { name: 'profilesILiked', query: PROFILES_I_LIKED_QUERY },
  { name: 'outgoingLikes', query: OUTGOING_LIKES_QUERY },
];
