# noinspection SpellCheckingInspectionForFile

TRUNCATE TABLE storage_property_value;

INSERT INTO storage_property_value (
    createdAt,
    storageId,
    storagePropertyId,
    storagePropertyOptionId,
    valueInteger,
    valueBoolean
)

SELECT *
FROM (

         -- ***************************************************************
-- 1. MULTISELECT / SELECT (Taxonomy) típusok: storagePropertyOptionId
-- ***************************************************************

-- ID 1: field_elhelyezkedes (MULTISELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             1 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_elhelyezkedes AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_elhelyezkedes_tid = spo.legacyId
         WHERE fd.field_elhelyezkedes_tid IS NOT NULL
         UNION ALL

-- ID 7: field_belogo (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             7 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_belogo AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_belogo_tid = spo.legacyId
         WHERE fd.field_belogo_tid IS NOT NULL
         UNION ALL

-- ID 12: field_ajtotipusa (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             12 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_ajtotipusa AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_ajtotipusa_tid = spo.legacyId
         WHERE fd.field_ajtotipusa_tid IS NOT NULL
         UNION ALL

-- ID 13: field_zartipusa (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             13 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_zartipusa AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_zartipusa_tid = spo.legacyId
         WHERE fd.field_zartipusa_tid IS NOT NULL
         UNION ALL

-- ID 14: field_epulethez (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             14 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_epulethez AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_epulethez_tid = spo.legacyId
         WHERE fd.field_epulethez_tid IS NOT NULL
         UNION ALL

-- ID 15: field_kapunyitas (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             15 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_kapunyitas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_kapunyitas_tid = spo.legacyId
         WHERE fd.field_kapunyitas_tid IS NOT NULL
         UNION ALL

-- ID 16: field_tarolonyitas (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             16 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_tarolonyitas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_tarolonyitas_tid = spo.legacyId
         WHERE fd.field_tarolonyitas_tid IS NOT NULL
         UNION ALL

-- ID 17: field_lepcso (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             17 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_lepcso AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_lepcso_tid = spo.legacyId
         WHERE fd.field_lepcso_tid IS NOT NULL
         UNION ALL

-- ID 20: field_konektor (SELECT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             20 AS storagePropertyId,
             spo.id AS storagePropertyOptionId,
             NULL AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_konektor AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24.storage_property_option AS spo ON fd.field_konektor_tid = spo.legacyId
         WHERE fd.field_konektor_tid IS NOT NULL
         UNION ALL

         -- ***************************************************************
-- 2. NUMBER típusok: Közvetlen érték és Taxonomy konverzió
-- ***************************************************************

-- ID 5: field_autoleparkol (NUMBER, Taxonomy konverzió: string -> INT)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             5 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             CAST(REGEXP_REPLACE(tdd.name, '[^0-9]', '') AS UNSIGNED) AS valueInteger, -- Csak számjegyek
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_autoleparkol AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_autoleparkol_tid = tdd.tid
         WHERE fd.field_autoleparkol_tid IS NOT NULL
         UNION ALL

-- ID 6: field_atlmagassag (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             6 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_atlmagassag_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_atlmagassag AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_atlmagassag_value IS NOT NULL
         UNION ALL

-- ID 8: field_szelesseg (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             8 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_szelesseg_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_szelesseg AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_szelesseg_value IS NOT NULL
         UNION ALL

-- ID 9: field_nyszelesseg (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             9 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_nyszelesseg_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_nyszelesseg AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_nyszelesseg_value IS NOT NULL
         UNION ALL

-- ID 10: field_magassag (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             10 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_magassag_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_magassag AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_magassag_value IS NOT NULL
         UNION ALL

-- ID 11: field_nymagassag (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             11 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_nymagassag_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_nymagassag AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_nymagassag_value IS NOT NULL
         UNION ALL

-- ID 30: field_hosszusag (NUMBER)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             30 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             fd.field_hosszusag_value AS valueInteger,
             NULL AS valueBoolean
         FROM raktar24_old.field_data_field_hosszusag AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_hosszusag_value IS NOT NULL
         UNION ALL

         -- ***************************************************************
-- 3. BOOLEAN típusok: Taxonomy konverzió (Nem/Nincs -> 0, Igen/Van -> 1)
-- ***************************************************************

-- ID 2: field_riaszto (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             2 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_riaszto AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_riaszto_tid = tdd.tid
         WHERE fd.field_riaszto_tid IS NOT NULL
         UNION ALL

-- ID 3: field_klimatizalas (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             3 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_klimatizalas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_klimatizalas_tid = tdd.tid
         WHERE fd.field_klimatizalas_tid IS NOT NULL
         UNION ALL

-- ID 4: field_vilagitas (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             4 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_vilagitas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_vilagitas_tid = tdd.tid
         WHERE fd.field_vilagitas_tid IS NOT NULL
         UNION ALL

-- ID 21: field_mosdo (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             21 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_mosdo AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_mosdo_tid = tdd.tid
         WHERE fd.field_mosdo_tid IS NOT NULL
         UNION ALL

-- ID 23: field_fust (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             23 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_fust AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_fust_tid = tdd.tid
         WHERE fd.field_fust_tid IS NOT NULL
         UNION ALL

-- ID 24: field_autokozvetlen (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             24 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_autokozvetlen AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_autokozvetlen_tid = tdd.tid
         WHERE fd.field_autokozvetlen_tid IS NOT NULL
         UNION ALL

-- ID 25: field_nulla24 (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             25 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_nulla24 AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_nulla24_tid = tdd.tid
         WHERE fd.field_nulla24_tid IS NOT NULL
         UNION ALL

-- ID 26: field_konterhasz (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             26 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_konterhasz AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_konterhasz_tid = tdd.tid
         WHERE fd.field_konterhasz_tid IS NOT NULL
         UNION ALL

-- ID 27: field_vizvetel (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             27 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_vizvetel AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_vizvetel_tid = tdd.tid
         WHERE fd.field_vizvetel_tid IS NOT NULL
         UNION ALL

-- ID 28: field_kamera (BOOLEAN, Taxonomy konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             28 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             IF(tdd.name IN ('Nem', 'Nincs'), 0, 1) AS valueBoolean
         FROM raktar24_old.field_data_field_kamera AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
                  JOIN raktar24_old.taxonomy_term_data AS tdd ON fd.field_kamera_tid = tdd.tid
         WHERE fd.field_kamera_tid IS NOT NULL
         UNION ALL

-- ***************************************************************
-- 4. BOOLEAN típusok: List konverzió (1->TRUE, 2->FALSE)
-- ***************************************************************

-- ID 18: field_biztositas (BOOLEAN, List konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             18 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             CASE fd.field_biztositas_value
                 WHEN '1' THEN 1 -- Igen
                 WHEN '2' THEN 0 -- Nem
             END AS valueBoolean
         FROM raktar24_old.field_data_field_biztositas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_biztositas_value IS NOT NULL
         UNION ALL

-- ID 19: field_teherlift (BOOLEAN, List konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             19 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             CASE fd.field_teherlift_value
                 WHEN '1' THEN 1
                 WHEN '2' THEN 0
             END AS valueBoolean
         FROM raktar24_old.field_data_field_teherlift AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_teherlift_value IS NOT NULL
         UNION ALL

-- ID 22: field_beallas (BOOLEAN, List konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             22 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             CASE fd.field_beallas_value
                 WHEN '1' THEN 1
                 WHEN '2' THEN 0
             END AS valueBoolean
         FROM raktar24_old.field_data_field_beallas AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_beallas_value IS NOT NULL
         UNION ALL

-- ID 29: field_futes (BOOLEAN, List konverzió)
         SELECT
             CURRENT_TIMESTAMP() AS createdAt,
             s.id AS storageId,
             29 AS storagePropertyId,
             NULL AS storagePropertyOptionId,
             NULL AS valueInteger,
             CASE fd.field_futes_value
                 WHEN '1' THEN 1
                 WHEN '2' THEN 0
             END AS valueBoolean
         FROM raktar24_old.field_data_field_futes AS fd
                  JOIN raktar24.storage AS s ON fd.entity_id = s.legacyId
         WHERE fd.field_futes_value IS NOT NULL

     ) AS `temp`;