import { graphql } from "@/gql";
import { NewsFragment } from "@/gql/graphql";

export type { NewsFragment, NewsIndexFragment, NewsListItemFragment } from "@/gql/graphql";

const NewsListItemFragmentDefinition = graphql(`
  fragment NewsListItem on NewsPage {
    __typename
    id
    slug
    title
    firstPublishedAt
    excerpt
    featuredImage {
      ...Image
    }
  }
`);

const NewsFragmentDefinition = graphql(`
  fragment News on NewsPage {
    __typename
    id
    slug
    seoTitle
    searchDescription
    title
    firstPublishedAt
    excerpt
    lead
    featuredImage {
      ...Image
    }
    body {
      ...Blocks
    }
  }
`);

const NewsIndexFragmentDefinition = graphql(`
  fragment NewsIndex on NewsIndex {
    __typename
    id
    slug
    seoTitle
    searchDescription
    title
    lead
  }
`);

export const newsIndexMetadataQuery = graphql(`
  query newsIndexMetadata {
    index: newsIndex {
      ... on NewsIndex {
        ...NewsIndex
      }
    }
  }
`);

export const newsQuery = graphql(`
  query news {
    index: newsIndex {
      ... on NewsIndex {
        ...NewsIndex
      }
    }
    news: pages(contentType: "news.NewsPage", order: "-first_published_at", limit: 1000) {
      ... on NewsPage {
        ...NewsListItem
      }
    }
  }
`);
