import { gql,TypedDocumentNode } from "@apollo/client";
import { PRODUCT_CORE_FRAGMENT } from "../fragments";
import { SearchProductsResponse } from "@/components/catalog/type";

export const SEARCH_PRODUCTS: TypedDocumentNode<SearchProductsResponse> = gql`
  ${PRODUCT_CORE_FRAGMENT}

  query SearchProducts(
    $query: String!
    $suggest: Boolean
    $sortKey: String
    $reverse: Boolean
    $first: Int
    $last: Int
    $after: String
    $before: String
    $channel: String
    $locale: String
    $filter: String
  ) {
    search(
      query: $query
      suggest: $suggest
      filter: $filter
      sortKey: $sortKey
      reverse: $reverse
      first: $first
      last: $last
      after: $after
      before: $before
      channel: $channel
      locale: $locale
      
    ) {

        totalCount
        edges {
            node { ...ProductCore }
        }
        pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
        }
        searchMetadata {
            originalQuery
            effectiveQuery
            resultMessage
            searchInsteadMessage
        }
    }
  }
`;