DROP TABLE IF EXISTS b_iblock_element_property;
DROP TABLE IF EXISTS b_iblock_property;
DROP TABLE IF EXISTS b_iblock_element;
DROP TABLE IF EXISTS b_file;

CREATE TABLE b_file (
    ID INT PRIMARY KEY,
    SUBDIR VARCHAR(255),
    FILE_NAME VARCHAR(255)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_element (
    ID INT PRIMARY KEY,
    IBLOCK_ID INT,
    IBLOCK_SECTION_ID INT NULL,
    WF_PARENT_ELEMENT_ID INT NULL,
    XML_ID VARCHAR(255) NULL,
    NAME VARCHAR(255),
    ACTIVE CHAR(1) DEFAULT 'Y',
    CODE VARCHAR(255),
    PREVIEW_PICTURE INT NULL,
    PREVIEW_TEXT TEXT,
    DETAIL_TEXT TEXT,
    DATE_CREATE DATETIME DEFAULT CURRENT_TIMESTAMP,
    TIMESTAMP_X DATETIME DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_property (
    ID INT PRIMARY KEY,
    IBLOCK_ID INT,
    NAME VARCHAR(255),
    CODE VARCHAR(255),
    ACTIVE CHAR(1) DEFAULT 'Y'
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_element_property (
    ID INT PRIMARY KEY AUTO_INCREMENT,
    IBLOCK_PROPERTY_ID INT,
    IBLOCK_ELEMENT_ID INT,
    VALUE TEXT,
    INDEX idx_element (IBLOCK_ELEMENT_ID),
    INDEX idx_property (IBLOCK_PROPERTY_ID)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

INSERT INTO b_file (ID, SUBDIR, FILE_NAME)
VALUES (1, 'local', 'doctor.png');

INSERT INTO b_iblock_element (ID, IBLOCK_ID, XML_ID, NAME, ACTIVE, CODE, PREVIEW_PICTURE, PREVIEW_TEXT, DETAIL_TEXT)
VALUES
    (1001, 91, '101', 'Иванов Иван Иванович', 'Y', 'ivanov-ivan', 1, 'Тестовый врач Bitrix', 'Локальное описание врача из Bitrix'),
    (2001, 91, 'review-1', 'Local review', 'Y', 'local-review', NULL, 'Отзыв', 'Отзыв из локального Bitrix');

INSERT INTO b_iblock_property (ID, IBLOCK_ID, NAME, CODE, ACTIVE)
VALUES
    (1, 91, 'Связанный врач', 'MEDIC', 'Y'),
    (2, 91, 'Текст отзыва', 'MESSAGE', 'Y'),
    (3, 91, 'Код услуги', 'KOD', 'Y'),
    (4, 91, 'Отзывы', 'LINK_REVIEWS', 'Y'),
    (5, 91, 'Прайс', 'LINK_PRICE_1', 'Y');

INSERT INTO b_iblock_element_property (IBLOCK_PROPERTY_ID, IBLOCK_ELEMENT_ID, VALUE)
VALUES
    (1, 2001, '1001'),
    (2, 2001, 'Локальный отзыв из Bitrix'),
    (3, 1001, '1001'),
    (4, 1001, '2001'),
    (5, 1001, '1001');
