import { PageLinkEnum } from "../pageLinks"

import type { Lang } from "@/constants/languages"
import type { System } from "../system"
import type { AllRequestResponse } from "../utils/all"
import type { Edges } from "../utils/edges"
import type { TypenameInterface } from "../utils/typename"

export type MenuItem = {
  lang: Lang
  linkText: string
  uid: string
  url: string
  originalUrl?: string
  subItems?: MenuItem[]
}

interface NavigationLink {
  system: {
    locale: Lang
    uid: string
  }
  title: string
  url: string
  web?: { original_url: string }
}

export interface AccountPageLink
  extends NavigationLink,
    TypenameInterface<PageLinkEnum.AccountPage> {}

export interface LoyaltyPageLink
  extends NavigationLink,
    TypenameInterface<PageLinkEnum.LoyaltyPage> {}

export interface ContentPageLink
  extends NavigationLink,
    TypenameInterface<PageLinkEnum.ContentPage> {}

export type PageLink = ContentPageLink | AccountPageLink | LoyaltyPageLink

interface Item {
  link_text: string
  pageConnection: Edges<PageLink>
}

interface ItemWithSubitem extends Item {
  sub_items: NavigationItem[]
}

export type NavigationItem = {
  item: Item | ItemWithSubitem
}

export type NavigationMyPages = {
  items: NavigationItem[]
  title: string
}

export type GetNavigationMyPagesData = {
  all_navigation_my_pages: AllRequestResponse<NavigationMyPages>
}

/** Refs Request */
type NavigationItemRef = {
  item: {
    pageConnection: Edges<System>
    sub_items: {
      item: {
        pageConnection: Edges<System>
      }
    }[]
  }
}

interface NavigationMyPagesRefs extends System {
  items: NavigationItemRef[]
}

export type GetNavigationMyPagesRefsData = {
  all_navigation_my_pages: AllRequestResponse<NavigationMyPagesRefs>
}
