interface ContentEntry {
    id: string
    active: boolean
    type: "page" | "block"
    name: string
    question?: string
    path: string
    insertTime?: string
    updateTime?: string
    alternativePaths?: {
        path: string
    }[]
    blocks?: ContentBlock[]
    meta?: ContentMeta
}
interface ContentMeta {
    title: string
    description: string
    keywords: string
    isArticle: boolean
    hasFAQ: boolean
    FAQ: {
        question: string
        answer: string
    }[]
}
interface ColumnsBlock {
    type: "columns"
    columns: BlockColumn[]
}

interface CTACol {
    upperHeadline: string
    description: string
    whiteHeadline: string
    redHeadline: string
    headlineArrangement: "row" | "column"
    callToActionButtons: CallToActionButton[]
}

type BlockColumnTypes =
    | {
          type: "image"
          images?: string[]
          imageHoverEffect: boolean
          imageMobileBackground: boolean
          forceFullHeight: boolean
      }
    | {
          type: "text"
          text?: string
      }
    | {
          type: "cta"
          cta: CTACol
      }
    | {
          type: "chapterDescription"
          chapterDescription: {
              title: string
              description: string
              type: number
          }
      }

type BlockColumn<T extends BlockColumnTypes["type"] | "unknown" = "unknown"> = T extends BlockColumnTypes["type"]
    ? Extract<BlockColumnTypes, { type: T }> & CommonBlockColumnProperties
    : BlockColumnTypes & CommonBlockColumnProperties

type CommonBlockColumnProperties = {
    colWidth?: 6 | 4 | -1
    verticalAlign: "top" | "middle" | "bottom"
    imageMobileBackground: boolean
    links?: BlockLink[]
}

enum CTATypes {
    PRIMARY = 0,
    SECONDARY = 1,
}
interface CallToActionButton {
    buttonText: string
    page: string
    ctaType: CTATypes
    buttonTarget: "_self" | "_blank"
}

interface GoogleMapsBlock {
    type: "googleMaps"
}

interface ProductSliderBlock {
    type: "productSlider"

    productSlider: { callToActionButtons: CallToAction[]; headline: string; topLine: string } & (
        | { productSource: "manual"; productIds: string[] }
        | { productSource: "category"; categoryId: string }
        | { productSource: "bestseller" }
        | { productSource: "newProducts" }
        | { productSource: "featured" }
        | { productSource: "discountend"; productIds: string[] }
    )
}

interface ImproveYourselfDescriptionBlock {
    type: "improveYourselfDescription"
    improveYourselfDescription: {
        upperDescription: string
        lowerDescription: string
        image: string
    }
}

interface FormBlock {
    type: "form"
    form: DBFormObj
}

interface PredefinedBlock {
    type: "predefinedBlock"
    predefinedBlock?: {
        id: string
    }
}

interface BlockLink {
    text: string
    url?: string
    file?: string
    target: "_self" | "_blank"
    style:
        | "primary"
        | "secondary"
        | "tertiary"
        | "internal"
        | "external"
        | "download"
        | "cardReservation"
        | "cardRegistration"
        | "batteryService"
}
interface HomepageBlock {
    type: "homepage"
    mainHomepage: {
        cta: CTACol
        image: string
    }
}
interface SplittedHomepageBlock {
    chapters: string[]
    type: "splittedHomepage"
}

interface ChapterPreview {
    type: "selfImprovementChapterPreview"
    selfImprovementChapterPreview: {
        chapter: string
        previewImage: string
    }[]
}

interface BKDFChallenge {
    slug: string
    type: number
    activeAt: Date
    title: string
    introduction: string[]
    images: {
        preview: string
        detailed: string
    }
    howItWorks: {
        invitation: string
        steps: Steps
    }
    blog: {
        blogId: string
        thumbnail: string
        sources: Source[]
    }
}

interface Source {
    source: string
    url: string
}
interface RatingPreview {
    type: "ratingPreview"
    ratingPreview: {
        ratings: {
            rating: string
        }[]
    }
}
interface Steps {
    type: "steps"
    steps: {
        color: "red"
        items: {
            nr: number
            title: string
            descriptions: string[]
            image: string
        }[]
    }
}
type ContentBlockType =
    | ColumnsBlock
    | GoogleMapsBlock
    | ProductSliderBlock
    | FormBlock
    | PredefinedBlock
    | SplittedHomepageBlock
    | selfImprovementChapterPreview
    | ImproveYourselfDescriptionBlock
    | HomepageBlock
    | RatingPreview
    | Steps

type ContentBlock<T extends ContentBlockType["type"] | "unknown" = "unknown"> = T extends ContentBlockType["type"]
    ? Extract<ContentBlockType, { type: T }> & CommonProperties
    : ContentBlockType & CommonProperties

enum ContentWidth {
    FULL = 0,
    NARROW = 1,
    NORMAL = 2,
}
interface CommonProperties {
    headline: string
    headlineH1: boolean
    headlineLink: string
    doublyLined: boolean
    subline: string
    crinkledSection: boolean
    additionalHeightBottom: boolean
    anchorId: string
    background: {
        color: "white" | "black"
        image: string
        minHeight: "none" | "normal" | "extended"
        overlay: boolean
        noVerticalPadding: boolean
        headerHeightUp: boolean
    }
    callToActionButtons: CallToActionButton[]

    contentWidth: ContentWidth
}

interface CallToAction {
    buttonText: string
    buttonLink: string
    buttonTarget: "_self" | "_blank"
}

interface Overlay {
    id: string
    content: typeof SvelteComponent
    title: typeof SvelteComponent | string
    properties: any
    closeOnParentOpen?: boolean
    active?: boolean
    hideTillDispatch?: boolean
}

interface HelpCenterQuestion {
    priority: boolean
    page: string
}
interface HelpCenterChapter {
    title: string
    slug: string
    brightIcon: string
    darkIcon: string
    questions: HelpCenterQuestion[]
}

interface ContactRequest {
    email: string
    name: string
    description: string
}

interface Contact {
    status: "new" | "inProgress" | "done"
    request: ContactRequest
}
