import { OrderSpec } from './order'

export const PUBLISHING_PLUGIN_ID = 'publishing' as const

export const PUBLISH_STATUS_FIELD_KEY = '_publishStatus' as const
export const PUBLISH_DATE_FIELD_KEY = '_publishDate' as const
export const DRAFT_DATE_FIELD_KEY = '_draftDate' as const

export enum PublishingStatus {
  DRAFT = 'DRAFT',
  PUBLISHED = 'PUBLISHED'
}

export interface PublishingPlugin {
  defaultStatus: PublishingStatus
}

export const GRID_APPLESS_PLUGIN_ID = 'gridAppless'

export interface GridApplessPlugin {
  isMigrated: boolean
}

export const SINGLES_PLUGIN_ID = 'singleItem' as const

export interface SinglesPlugin {
  singleItemId: string
}

export const URLIZED_PLUGIN_ID = 'urlized' as const

export enum UrlizedFormat {
  PLAIN = 'plain',
  ORIGINAL = 'original'
}

export interface UrlizedPlugin {
  format: UrlizedFormat
}

export const MULTILINGUAL_PLUGIN_ID = 'multilingual' as const

export interface MultilingualPlugin {
  translatable: string[]
}

export const SHARED_PLUGIN_ID = 'shared' as const

export interface SharedPlugin {}

export const PAGE_LINK_PLUGIN_ID = 'persistentPageLink' as const
export interface PageLinkPlugin {
  isPersisted: boolean
  isUpdatable: boolean
}

export const CMS_PLUGIN_ID = 'cms'
export interface CmsPlugin {
  siteSort?: {
    sort: OrderSpec[]
  }
}

export const CATALOG_PLUGIN_ID = 'CATALOG'
export interface CatalogOptions {
  name?: string
  price?: string
  url?: string | null
  description?: string | null
  image?: string | null
  quantity?: string | null
}

export interface CatalogPlugin {
  catalogOptions?: CatalogOptions
}

export const CATEGORIES_PLUGIN_ID = 'categories'
export interface CategoriesPlugin {}

export interface KnownSchemaPlugins {
  [PUBLISHING_PLUGIN_ID]?: PublishingPlugin
  [GRID_APPLESS_PLUGIN_ID]?: GridApplessPlugin
  [SINGLES_PLUGIN_ID]?: SinglesPlugin
  [URLIZED_PLUGIN_ID]?: UrlizedPlugin
  [MULTILINGUAL_PLUGIN_ID]?: MultilingualPlugin
  [SHARED_PLUGIN_ID]?: SharedPlugin
  [PAGE_LINK_PLUGIN_ID]?: PageLinkPlugin
  [CMS_PLUGIN_ID]?: CmsPlugin
  [CATALOG_PLUGIN_ID]?: CatalogPlugin
  [CATEGORIES_PLUGIN_ID]?: CategoriesPlugin
}

export type SchemaPlugins = KnownSchemaPlugins & Record<string, object>

export type SchemaPluginId = keyof KnownSchemaPlugins
export type SchemaPlugin = Required<KnownSchemaPlugins>[SchemaPluginId]
