import type { AnyRegularField } from "./types"

import type { GroupField } from "./group"
import type { SliceZone } from "./sliceZone"
import type { TimestampField } from "./timestamp"

/**
 * Document metadata for a translation of a Prismic document.
 */
export interface AlternateLanguage<TypeEnum = string, LangEnum = string> {
	id: string
	uid?: string
	type: TypeEnum
	lang: LangEnum
}

/**
 * Metadata for Prismic document
 */
export interface PrismicDocumentHeader<TypeEnum = string, LangEnum = string> {
	/**
	 * The unique identifier for the document. Guaranteed to be unique among all
	 * documents in the Prismic repository.
	 */
	id: string
	/**
	 * The unique identifier for the document. Guaranteed to be unique among all
	 * Prismic documents of the same type.
	 */
	uid: string | null
	/**
	 * Url that refers to document.
	 */
	url: string | null
	/**
	 * Type of the document.
	 */
	type: TypeEnum
	/**
	 * Href for document.
	 */
	href: string
	/**
	 * Tags associated with document.
	 */
	tags: string[]
	/**
	 * The timestamp at which the document was first published.
	 */
	first_publication_date: TimestampField<"filled">
	/**
	 * The timestamp at which the document was last published.
	 */
	last_publication_date: TimestampField<"filled">
	/**
	 * Slugs associated with document.
	 *
	 * @deprecated Slugs are a deprecated feature used before the UID field was
	 *   introduced. Migrate to the UID field. For more details, see
	 *   https://community.prismic.io/t/what-are-slugs/6493
	 */
	slugs: string[]
	/**
	 * Documents that are related to this document.
	 */
	linked_documents: unknown[] // TODO: Not sure of the type for this one
	/**
	 * Language of document.
	 */
	lang: LangEnum
	/**
	 * Array to access alternate language versions for document.
	 */
	alternate_languages: AlternateLanguage<TypeEnum, LangEnum>[]
}

/**
 * A Prismic document served through REST API v2.
 *
 * @see More details on custom types: {@link https://prismic.io/docs/custom-types}
 */
export interface PrismicDocument<
	DataInterface extends Record<
		string,
		AnyRegularField | GroupField | SliceZone
		// eslint-disable-next-line @typescript-eslint/no-explicit-any
	> = Record<string, any>,
	TypeEnum = string,
	LangEnum = string,
> extends PrismicDocumentHeader<TypeEnum, LangEnum> {
	/**
	 * Data contained in the document.
	 */
	data: DataInterface
}

/**
 * A Prismic document served through REST API v2. Does not contain a UID (a
 * unique identifier).
 *
 * @see More details on custom types: {@link https://prismic.io/docs/custom-types}
 * @see More details on the UID field: {@link https://prismic.io/docs/uid}
 */
export interface PrismicDocumentWithoutUID<
	DataInterface extends Record<
		string,
		AnyRegularField | GroupField | SliceZone
		// eslint-disable-next-line @typescript-eslint/no-explicit-any
	> = Record<string, any>,
	TypeEnum = string,
	LangEnum = string,
> extends PrismicDocument<DataInterface, TypeEnum, LangEnum> {
	/**
	 * This document does not have a UID field. This property will always be
	 * `null`.
	 *
	 * The unique identifier for the document. Guaranteed to be unique among all
	 * Prismic documents of the same type.
	 */
	uid: null
}

/**
 * A Prismic document served through REST API v2. Contains a UID (a unique
 * identifier).
 *
 * @see More details on custom types: {@link https://prismic.io/docs/custom-types}
 * @see More details on the UID field: {@link https://prismic.io/docs/uid}
 */
export interface PrismicDocumentWithUID<
	DataInterface extends Record<
		string,
		AnyRegularField | GroupField | SliceZone
		// eslint-disable-next-line @typescript-eslint/no-explicit-any
	> = Record<string, any>,
	TypeEnum = string,
	LangEnum = string,
> extends PrismicDocument<DataInterface, TypeEnum, LangEnum> {
	/**
	 * The unique identifier for the document. Guaranteed to be unique among all
	 * Prismic documents of the same type.
	 */
	uid: string
}
