-- ============================================
-- Premise Data Generation Script
-- ============================================
-- This script creates fake users and premises based on existing materials, nodes, and packaging


-- ============================================
-- Insert Premises using existing materials and packaging
-- ============================================
START TRANSACTION;
-- Premise 1: Gearbox housing blank from Linde China | john.doe@company.com | COMPLETED (0-Month-old)
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '28152640129'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '28152640129')),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'COMPLETED',
        1200,
        400,
        700,
        677000,
        'MM',
        'G',
        2,
        TRUE,
        TRUE,
        NOW());

SET @premise_id_1 = LAST_INSERT_ID();

-- Premise 2: Gearbox housing blank from Linde China | john.doe@company.com | COMPLETED (3-Month-old)
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '28152640129'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '28152640129')),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'COMPLETED',
        1200,
        790,
        700,
        677000,
        'MM',
        'G',
        1,
        TRUE,
        TRUE,
        DATE_SUB(NOW(), INTERVAL 3 MONTH));
SET @premiseId2 = LAST_INSERT_ID();

-- Premise 3: planet gear carrier blank 'stage 1 from Linde China | john.doe@company.com | DRAFT
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '8222640822'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '8222640822')),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'DRAFT',
        1200,
        790,
        700,
        677000,
        'MM',
        'G',
        3,
        TRUE,
        TRUE,
        NOW());
SET @premiseId3 = LAST_INSERT_ID();


-- Premise 4: planet gear carrier blank 'stage 1 from Linde China | john.doe@company.com | COMPLETED
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '8222640822'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '8222640822')),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'COMPLETED',
        1200,
        790,
        700,
        677000,
        'MM',
        'G',
        1,
        TRUE,
        TRUE,
        NOW());
SET @premiseId4 = LAST_INSERT_ID();

-- Premise 5: planet gear carrier blank 'stage 1 from Linde China | sarah.smith@company.com | DRAFT
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '8222640822'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '8222640822')),
        (SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'DRAFT',
        1200,
        790,
        700,
        677000,
        'MM',
        'KG',
        1,
        TRUE,
        TRUE,
        NOW());
SET @premiseId5 = LAST_INSERT_ID();


-- Premise 6: wheel hub from Linde China | sarah.smith@company.com | DRAFT
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '3064540201'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '3064540201')),
        (SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'DRAFT',
        1200,
        790,
        700,
        677000,
        'MM',
        'KG',
        1,
        TRUE,
        TRUE,
        NOW());
SET @premiseId6 = LAST_INSERT_ID();


-- Premise 7: wheel hub from Linde China | sarah.smith@company.com | COMPLETED
INSERT INTO premise (material_id,
                     supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '3064540201'),
        (SELECT id FROM node WHERE external_mapping_id = 'LX'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '3064540201')),
        (SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'COMPLETED',
        1200,
        790,
        700,
        677000,
        'MM',
        'KG',
        4,
        TRUE,
        TRUE,
        NOW());
SET @premiseId7 = LAST_INSERT_ID();


-- Premise 8: Gearbox housing blank from Linde China | john.doe@company.com | DRAFT
INSERT INTO premise (material_id,
                     user_supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '28152640129'),
        (SELECT id FROM sys_user_node WHERE name = 'My Supplier 1'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '28152640129')),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'DRAFT',
        1200,
        790,
        700,
        677000,
        'MM',
        'G',
        8,
        TRUE,
        TRUE,
        NOW());
SET @premiseId8 = LAST_INSERT_ID();


-- Premise 9: gearbox housing blank 'GR4H-10 from Linde China | sarah.smith@company.com | COMPLETED
INSERT INTO premise (material_id,
                     user_supplier_node_id,
                     geo_lat,
                     geo_lng,
                     country_id,
                     packaging_id,
                     user_id,
                     material_cost,
                     is_fca_enabled,
                     oversea_share,
                     hs_code,
                     tariff_rate,
                     state,
                     individual_hu_length,
                     individual_hu_height,
                     individual_hu_width,
                     individual_hu_weight,
                     hu_displayed_dimension_unit,
                     hu_displayed_weight_unit,
                     hu_unit_count,
                     hu_stackable,
                     hu_mixable,
                     updated_at)
VALUES ((SELECT id FROM material WHERE part_number = '28152640129'),
        (SELECT id FROM sys_user_node WHERE name = 'My Supplier 2'),
        24.489,
        118.1478,
        (SELECT id FROM country WHERE iso_code = 'CN'),
        (SELECT id FROM packaging WHERE material_id = (SELECT id FROM material WHERE part_number = '28152640129')),
        (SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'),
        2850.50,
        TRUE,
        0.75,
        '84839089',
        0.065,
        'COMPLETED',
        1200,
        790,
        700,
        677000,
        'MM',
        'G',
        1,
        TRUE,
        TRUE,
        NOW());
SET @premiseId9 = LAST_INSERT_ID();

COMMIT;