from .infoenums import PartitionInfo

OTA_RESCUE_LOGGER_NAME = "ecp-ota-updater-rescue-os"

ROOT_FS_ARCHIVE_NAME = "rootfs.tar.xz"  # do not change! (name is linked with otadebpayload/settings.py -> ROOT_FS_ARCHIVE_NAME)
MTD_BOOTLOADER_PATH = "/dev/mtd0"
SD_CARD_BLOCKDEVICE_NAME = "mmcblk0"

EXPECTED_NUMBER_OF_PARTITIONS = 4

UBOOT_PARTITION = "boot"
ROOTFS_0_PARTITION = "rootfs.0"
ROOTFS_1_PARTITION = "rootfs.1"
PERSISTENT_DATA_PARTITION = "persistent-data"
BACKUP_DATA_PARTITION = "data-rescue"

MOUNT_POINT = "/mnt/"
MOUNT_POINT_PERSISTENT_DATA = MOUNT_POINT + PERSISTENT_DATA_PARTITION
MOUNT_POINT_BOOT = MOUNT_POINT + UBOOT_PARTITION
MOUNT_POINT_ROOTFS_0 = MOUNT_POINT + ROOTFS_0_PARTITION
MOUNT_POINT_ROOTFS_1 = MOUNT_POINT + ROOTFS_1_PARTITION
MOUNT_POINT_BACKUP = MOUNT_POINT + BACKUP_DATA_PARTITION

PARTITION_BOOT_ID = 1
PARTITION_ROOTFS0_ID = 2
PARTITION_ROOTFS1_ID = 3
PARTITION_DATA_ID = 4

# https://gitlab.evtec.ch/platform/meta-evtec/-/blob/e8ccf4d412420edcc6242b575ee4368ed466badc/wic/sdimage-evtec.wks
PARTITION_LAYOUT = {
    PARTITION_BOOT_ID: {
        PartitionInfo.LABEL: UBOOT_PARTITION,
        PartitionInfo.START: 4,
        PartitionInfo.END: 30,
    },
    PARTITION_ROOTFS0_ID: {
        PartitionInfo.LABEL: ROOTFS_0_PARTITION,
        PartitionInfo.START: 32,
        PartitionInfo.END: 2080,
    },
    PARTITION_ROOTFS1_ID: {
        PartitionInfo.LABEL: ROOTFS_1_PARTITION,
        PartitionInfo.START: 2080,
        PartitionInfo.END: 4128,
    },
}

PERSISTENT_DATA_PARTITION_START = 4128  # [MiB]

UBOOT_CONFIGURATION_SCRIPTS = ["boot.scr", "boot_selection.scr"]
UBOOT_FILE_NAME_S = "u-boot.imx-solo"
UBOOT_FILE_NAME_DL = "u-boot.imx-duallite"

ECP_OTA_BACKUP_FOLDER = "ota-ecp-data"
ECP_OTA_DOWNLOAD_FOLDER = "ota-ecp-download"
EVTEC_ECP_DATA = "evtec-ecp-data"
BACKED_UP_LOCATIONS = [
    "config",
    "media/custom-graphics",
    "media/promotion-screen-graphics",
]
BACKUP_FOLDER_MAPPING = [
    ("icons-whitelabel", "media/custom-graphics"),
    ("promotion-screens", "media/promotion-screen-graphics"),
    ("cert", "certificates/delta-fm"),
]
CONFIGURATION_FOLDER_MAPPING = [
    (
        "config",
        "config",
    ),  # This configuration was upgraded to ECP by the migration service
]


OTA_MAIN_BOARD_API_PORT = 3030
OTA_MAIN_BOARD_END_POINT = "state"

SCREEN_PORT = 8090
SCREEN_TEMPLATE = "otarescue-firmware-update.html"
UPDATE_PICTURE = "rescueUpdatePicture.raw"

STATUS_FILE_NAME = "status.json"
