-- XBRL Reports
CREATE TABLE IF NOT EXISTS `_XBRLReports` (
    `_id` INT(11) NOT NULL AUTO_INCREMENT,
    `_accYearStart` DATE NOT NULL,
    `_accYearEnd` DATE NOT NULL,
    `_orgNo` VARCHAR(255) NOT NULL,
    `_reportType` ENUM('k2') NOT NULL DEFAULT 'k2',
    `_version` VARCHAR(255) NOT NULL,
    `_language` VARCHAR(5) NOT NULL DEFAULT 'sv',
    PRIMARY KEY (`_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `_XBRLReportElements` (
    `_id` INT(11) NOT NULL AUTO_INCREMENT,
    `_reportID` INT(11) NOT NULL,
    `_name` VARCHAR(255) NOT NULL,
    `_value` VARCHAR(255) NOT NULL,
    `_contextRef` VARCHAR(255) NOT NULL,
    `_unitRef` VARCHAR(255) NOT NULL,
    `_decimals` VARCHAR(5) NOT NULL DEFAULT 'INF',
    `_isTuple` TINYINT(1) NOT NULL DEFAULT '0',
    `_parentID` INT(11) NOT NULL DEFAULT '0',
    `_parentName` VARCHAR(255) NOT NULL DEFAULT '',
    `_noteRef` VARCHAR(255) NOT NULL DEFAULT '',
    `_index` INT(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`_id`),
    FOREIGN KEY (`_reportID`) REFERENCES `_XBRLReports` (`_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `_XBRLReportContexts` (
    `_reportID` INT(11) NOT NULL,
    `_contextID` VARCHAR(255) NOT NULL,
    `_entityIdentifier` VARCHAR(255) NOT NULL,
    `_entityScheme` VARCHAR(255) NOT NULL,
    `_periodType` ENUM('duration', 'instant', 'forever') NOT NULL DEFAULT 'duration',
    `_periodStartDate` DATE NOT NULL DEFAULT '0000-00-00',
    `_periodEndDate` DATE NOT NULL DEFAULT '0000-00-00',
    `_periodInstant` DATE NOT NULL DEFAULT '0000-00-00',
    `_index` INT(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`_reportID`, `_contextID`),
    FOREIGN KEY (`_reportID`) REFERENCES `_XBRLReports` (`_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `_XBRLReportUnits` (
    `_reportID` INT(11) NOT NULL,
    `_unitID` VARCHAR(255) NOT NULL,
    `_measure` VARCHAR(255) NOT NULL,
    `_index` INT(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`_reportID`, `_unitID`),
    FOREIGN KEY (`_reportID`) REFERENCES `_XBRLReports` (`_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
-- XBRL Taxonomies
CREATE TABLE IF NOT EXISTS `_XBRLTaxonomies` (
    `_id` INT(11) NOT NULL AUTO_INCREMENT,
    `_reportType` VARCHAR(255) NOT NULL,
    `_version` VARCHAR(255) NOT NULL,
    `_revision` VARCHAR(255) NOT NULL,
    `_isFinal` TINYINT(1) NOT NULL DEFAULT '1',
    `_language` VARCHAR(255) NOT NULL DEFAULT 'sv',
    PRIMARY KEY (`_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `_XBRLTaxonomyElements` (
    `_id` INT(11) NOT NULL AUTO_INCREMENT,
    `_xbrlTaxonomyID` INT(11) NOT NULL,
    `_section` VARCHAR(255) NOT NULL,
    `_rowID` INT(11) NOT NULL,
    `_rowNo` INT(11) NOT NULL,
    `_rowLabel` VARCHAR(255) NOT NULL,
    `_rowLabelAlt` TEXT NOT NULL,
    `_elementName` VARCHAR(255) NOT NULL,
    `_from` VARCHAR(255) NOT NULL,
    `_standardLabel` VARCHAR(255) NOT NULL,
    `_isAbstract` TINYINT(1) NOT NULL DEFAULT '0',
    `_dataType` VARCHAR(255) NOT NULL,
    `_balance` VARCHAR(255) NOT NULL,
    `_periodType` ENUM('duration', 'instant', 'forever', 'na') NOT NULL DEFAULT 'duration',
    `_type` VARCHAR(255) NOT NULL,
    `_documentation` TEXT,
    `_extendedDocumentation` TEXT,
    `_parentID` INT(11) NOT NULL DEFAULT '0',
    `_level` INT(11) NOT NULL DEFAULT '0',
    `_parentTree` VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY (`_id`),
    FOREIGN KEY (`_xbrlTaxonomyID`) REFERENCES `_XBRLTaxonomies` (`_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
-- products
CREATE TABLE IF NOT EXISTS `products` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `price` DECIMAL(10, 2) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
-- _SchemaVersions
CREATE TABLE IF NOT EXISTS `_SchemaVersions` (
    `_id` INT(11) NOT NULL AUTO_INCREMENT,
    `_version` INT(11) NOT NULL,
    `_appliedAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;