-- First, create some fake users since premise table requires user_id
INSERT INTO sys_user (workday_id, email, firstname, lastname, is_active)
VALUES ('USR001', 'john.doe@company.com', 'John', 'Doe', TRUE),
       ('USR002', 'sarah.smith@company.com', 'Sarah', 'Smith', TRUE),
       ('USR003', 'mike.johnson@company.com', 'Mike', 'Johnson', TRUE),
       ('USR004', 'anna.mueller@company.com', 'Anna', 'Mueller', TRUE),
       ('USR005', 'david.chen@company.com', 'David', 'Chen', TRUE)
ON DUPLICATE KEY UPDATE email = VALUES(email);

INSERT INTO sys_group(group_name, group_description)
VALUES ('none', 'no rights');
INSERT INTO sys_group(group_name, group_description)
VALUES ('basic', 'Login, generate reports');
INSERT INTO sys_group(group_name, group_description)
VALUES ('calculation', 'Login, generate reports, do calculations');
INSERT INTO sys_group(group_name, group_description)
VALUES ('freight', 'Login, generate reports, edit freight rates');
INSERT INTO sys_group(group_name, group_description)
VALUES ('packaging', 'Login, generate reports, edit packaging data');
INSERT INTO sys_group(group_name, group_description)
VALUES ('material', 'Login, generate reports, edit material data');
INSERT INTO sys_group(group_name, group_description)
VALUES ('super',
        'Login, generate reports, do calculations, edit freight rates, edit packaging data');
INSERT INTO sys_group(group_name, group_description)
VALUES ('service', 'Register API Tokens');
INSERT INTO sys_group(group_name, group_description)
VALUES ('right-management',
        'Add/Remove users, groups, etc.');

INSERT INTO sys_user_group_mapping (group_id, user_id)
VALUES ((SELECT id FROM sys_group WHERE group_name = 'super'),
        (SELECT id FROM sys_user WHERE email = 'john.doe@company.com'));

INSERT INTO sys_user_group_mapping (group_id, user_id)
VALUES ((SELECT id FROM sys_group WHERE group_name = 'basic'),
        (SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'));

INSERT INTO sys_user_group_mapping (group_id, user_id)
VALUES ((SELECT id FROM sys_group WHERE group_name = 'calculation'),
        (SELECT id FROM sys_user WHERE email = 'mike.johnson@company.com'));

INSERT INTO sys_user_group_mapping (group_id, user_id)
VALUES ((SELECT id FROM sys_group WHERE group_name = 'freight'),
        (SELECT id FROM sys_user WHERE email = 'anna.mueller@company.com'));

INSERT INTO sys_user_group_mapping (group_id, user_id)
VALUES ((SELECT id FROM sys_group WHERE group_name = 'packaging'),
        (SELECT id FROM sys_user WHERE email = 'david.chen@company.com'));

INSERT INTO sys_user_node (user_id, country_id, name, address, geo_lat, geo_lng, is_deprecated)
VALUES ((SELECT id FROM sys_user WHERE email = 'john.doe@company.com'),
        (SELECT id FROM country WHERE iso_code = 'CN'),
        'My Supplier 1', 'My Road 1, 1234 MyCity',
        24.489,
        118.1478, false);

INSERT INTO sys_user_node (user_id, country_id, name, address, geo_lat, geo_lng, is_deprecated)
VALUES ((SELECT id FROM sys_user WHERE email = 'sarah.smith@company.com'),
        (SELECT id FROM country WHERE iso_code = 'CN'),
        'My Supplier 2', 'My Road 2, 1234 MyCity',
        24.489,
        118.1478, false);
