// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
package com.coldboreballisticsllc.scopedope.label.format

/** All label formats known to the app. */
object LabelFormats {

    // ── Circle ────────────────────────────────────────────────────────────────

    val CIRCLE_50MM = LabelFormat(
        id                  = "circle_50mm",
        displayName         = "1.5\" Round (50 mm)",
        shape               = LabelShape.Circle(diameterMm = 50f),
        sizeGroup           = LabelSizeGroup.CIRCLE_50MM,
        columns             = 1,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── 50×30 mm ─────────────────────────────────────────────────────────────

    val RECT_50X30_PORTRAIT = LabelFormat(
        id                  = "rect_50x30_portrait",
        displayName         = "50×30 Portrait",
        shape               = LabelShape.Rectangle(widthMm = 30f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X30,
        columns             = 1,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X30_LANDSCAPE = LabelFormat(
        id                  = "rect_50x30_landscape",
        displayName         = "50×30 Landscape",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 30f),
        sizeGroup           = LabelSizeGroup.RECT_50X30,
        columns             = 2,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X30_LANDSCAPE_1COL = LabelFormat(
        id                  = "rect_50x30_landscape_1col",
        displayName         = "50×30 Landscape 1 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 30f),
        sizeGroup           = LabelSizeGroup.RECT_50X30,
        columns             = 1,
        maxEntries          = 4,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── 50×50 mm Square ──────────────────────────────────────────────────────

    val RECT_50X50_LANDSCAPE = LabelFormat(
        id                  = "rect_50x50_landscape",
        displayName         = "50×50 Square 2 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X50,
        columns             = 2,
        maxEntries          = 16,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X50_LANDSCAPE_1COL = LabelFormat(
        id                  = "rect_50x50_landscape_1col",
        displayName         = "50×50 Square 1 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X50,
        columns             = 1,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── 40×70 mm ─────────────────────────────────────────────────────────────

    val RECT_40X70_PORTRAIT = LabelFormat(
        id                  = "rect_40x70_portrait",
        displayName         = "40×70 Portrait",
        shape               = LabelShape.Rectangle(widthMm = 40f, heightMm = 70f),
        sizeGroup           = LabelSizeGroup.RECT_40X70,
        columns             = 1,
        maxEntries          = 10,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // 40×70 landscape: rendered 70mm wide, rotated 90° by rotateBitmapForPrint to fit the 40mm roll.
    val RECT_40X70_LANDSCAPE_1COL = LabelFormat(
        id                  = "rect_40x70_landscape_1col",
        displayName         = "40×70 Landscape 1 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 40f),
        sizeGroup           = LabelSizeGroup.RECT_40X70,
        columns             = 1,
        maxEntries          = 3,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_40X70_LANDSCAPE_2COL = LabelFormat(
        id                  = "rect_40x70_landscape_2col",
        displayName         = "40×70 Landscape 2 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 40f),
        sizeGroup           = LabelSizeGroup.RECT_40X70,
        columns             = 2,
        maxEntries          = 6,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_40X70_LANDSCAPE_3COL = LabelFormat(
        id                  = "rect_40x70_landscape_3col",
        displayName         = "40×70 Landscape 3 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 40f),
        sizeGroup           = LabelSizeGroup.RECT_40X70,
        columns             = 3,
        maxEntries          = 9,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── 50×70 mm ─────────────────────────────────────────────────────────────

    val RECT_50X70_PORTRAIT_1COL = LabelFormat(
        id                  = "rect_50x70_portrait_1col",
        displayName         = "50×70 Portrait 1 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 70f),
        sizeGroup           = LabelSizeGroup.RECT_50X70,
        columns             = 1,
        maxEntries          = 10,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X70_PORTRAIT_2COL = LabelFormat(
        id                  = "rect_50x70_portrait_2col",
        displayName         = "50×70 Portrait 2 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 70f),
        sizeGroup           = LabelSizeGroup.RECT_50X70,
        columns             = 2,
        maxEntries          = 20,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // 50×70 landscape: rendered 70mm wide, rotated 90° by rotateBitmapForPrint to fit the 50mm roll.
    val RECT_50X70_LANDSCAPE_1COL = LabelFormat(
        id                  = "rect_50x70_landscape_1col",
        displayName         = "50×70 Landscape 1 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X70,
        columns             = 1,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X70_LANDSCAPE_2COL = LabelFormat(
        id                  = "rect_50x70_landscape_2col",
        displayName         = "50×70 Landscape 2 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X70,
        columns             = 2,
        maxEntries          = 12,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X70_LANDSCAPE_3COL = LabelFormat(
        id                  = "rect_50x70_landscape_3col",
        displayName         = "50×70 Landscape 3 col",
        shape               = LabelShape.Rectangle(widthMm = 70f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X70,
        columns             = 3,
        maxEntries          = 24,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── 50×80 mm ─────────────────────────────────────────────────────────────

    val RECT_50X80_PORTRAIT_1COL = LabelFormat(
        id                  = "rect_50x80_portrait_1col",
        displayName         = "50×80 Portrait 1 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 80f),
        sizeGroup           = LabelSizeGroup.RECT_50X80,
        columns             = 1,
        maxEntries          = 10,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X80_PORTRAIT_2COL = LabelFormat(
        id                  = "rect_50x80_portrait_2col",
        displayName         = "50×80 Portrait 2 col",
        shape               = LabelShape.Rectangle(widthMm = 50f, heightMm = 80f),
        sizeGroup           = LabelSizeGroup.RECT_50X80,
        columns             = 2,
        maxEntries          = 20,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // 50×80 landscape: rendered 80mm wide, rotated 90° by rotateBitmapForPrint to fit the 50mm roll.
    val RECT_50X80_LANDSCAPE_1COL = LabelFormat(
        id                  = "rect_50x80_landscape_1col",
        displayName         = "50×80 Landscape 1 col",
        shape               = LabelShape.Rectangle(widthMm = 80f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X80,
        columns             = 1,
        maxEntries          = 8,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X80_LANDSCAPE_2COL = LabelFormat(
        id                  = "rect_50x80_landscape_2col",
        displayName         = "50×80 Landscape 2 col",
        shape               = LabelShape.Rectangle(widthMm = 80f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X80,
        columns             = 2,
        maxEntries          = 16,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    val RECT_50X80_LANDSCAPE_3COL = LabelFormat(
        id                  = "rect_50x80_landscape_3col",
        displayName         = "50×80 Landscape 3 col",
        shape               = LabelShape.Rectangle(widthMm = 80f, heightMm = 50f),
        sizeGroup           = LabelSizeGroup.RECT_50X80,
        columns             = 3,
        maxEntries          = 24,
        supportedPrinterIds = setOf("niimbot_b1", "niimbot_b21_pro"),
    )

    // ── Indexes ───────────────────────────────────────────────────────────────

    val all: List<LabelFormat> = listOf(
        CIRCLE_50MM,
        RECT_50X30_PORTRAIT, RECT_50X30_LANDSCAPE, RECT_50X30_LANDSCAPE_1COL,
        RECT_50X50_LANDSCAPE, RECT_50X50_LANDSCAPE_1COL,
        RECT_40X70_PORTRAIT,
        RECT_40X70_LANDSCAPE_1COL, RECT_40X70_LANDSCAPE_2COL, RECT_40X70_LANDSCAPE_3COL,
        RECT_50X70_PORTRAIT_1COL, RECT_50X70_PORTRAIT_2COL,
        RECT_50X70_LANDSCAPE_1COL, RECT_50X70_LANDSCAPE_2COL, RECT_50X70_LANDSCAPE_3COL,
        RECT_50X80_PORTRAIT_1COL, RECT_50X80_PORTRAIT_2COL,
        RECT_50X80_LANDSCAPE_1COL, RECT_50X80_LANDSCAPE_2COL, RECT_50X80_LANDSCAPE_3COL,
    )

    /** Formats grouped by physical label roll size, ordered for display. */
    val allBySizeGroup: Map<LabelSizeGroup, List<LabelFormat>> = all.groupBy { it.sizeGroup }

    /** The default format shown when a size group is first selected. */
    val defaultForSizeGroup: Map<LabelSizeGroup, LabelFormat> = mapOf(
        LabelSizeGroup.CIRCLE_50MM to CIRCLE_50MM,
        LabelSizeGroup.RECT_50X30  to RECT_50X30_PORTRAIT,
        LabelSizeGroup.RECT_50X50  to RECT_50X50_LANDSCAPE,
        LabelSizeGroup.RECT_40X70  to RECT_40X70_PORTRAIT,
        LabelSizeGroup.RECT_50X70  to RECT_50X70_PORTRAIT_1COL,
        LabelSizeGroup.RECT_50X80  to RECT_50X80_PORTRAIT_1COL,
    )
}
