import type { Lang } from "@/constants/languages"
import type { EdgesWithTotalCount } from "../utils/edges"
import type { Typename } from "../utils/typename"

export enum Section {
  ContactBlockSectionsExtraInfo = "ContactBlockSectionsExtraInfo",
  ContactBlockSectionsMailingAddress = "ContactBlockSectionsMailingAddress",
  ContactBlockSectionsPhone = "ContactBlockSectionsPhone",
  ContactBlockSectionsTitle = "ContactBlockSectionsTitle",
  ContactBlockSectionsVisitingAddress = "ContactBlockSectionsVisitingAddress",
}

type ExtraInfo = Typename<
  {
    extra_info: {
      text: string
    }
  },
  Section.ContactBlockSectionsExtraInfo
>

type MailingAddress = Typename<
  {
    mailing_address: {
      city: string
      country: string
      name: string
      street: string
      zip: string
    }
  },
  Section.ContactBlockSectionsMailingAddress
>

type Phone = Typename<
  {
    phone: {
      number: number
      title: string
    }
  },
  Section.ContactBlockSectionsPhone
>

type Title = Typename<
  {
    title: {
      text: string
    }
  },
  Section.ContactBlockSectionsTitle
>

type VisitingAddress = Typename<
  {
    visiting_address: {
      city: string
      country: string
      street: string
      zip: string
    }
  },
  Section.ContactBlockSectionsVisitingAddress
>

type Sections = ExtraInfo | MailingAddress | Phone | Title | VisitingAddress

export type ContactNode = {
  sections: Sections[]
  system: {
    locale: Lang
    uid: string
  }
}

export type Contact = {
  contact: {
    contactConnection: EdgesWithTotalCount<ContactNode>
  }
}
