-- Add Saudi Arabia and United Arab Emirates

INSERT INTO "product-currencies" (iso3char, exchange_rate) VALUES ('AED', 0.41);
INSERT INTO "i18n-currencies" (iso3char, symbol, fractional_parts, exchange_rate, locale) VALUES (
    'AED',
    'Dh',
    0,
    0.41, -- exchange rate value will be updated by Riksbanken API so unimportant
    'en_US.UTF-8' -- locale not used anywhere; I opt for standard en_US instead of en_AE
);

INSERT INTO locales (value, name, fallback_id) VALUES
    ('en_AE', 'English (United Arab Emirates)', (select id from locales where value = 'en_GB'));
INSERT INTO locales (value, name, fallback_id) VALUES
    ('en_SA', 'English (Saudi Arabia)', (select id from locales where value = 'en_GB'));

-- Will confirm price adjustment values with Pinar after live on staging
INSERT INTO markets (name, vat, currency, price_adjustment) VALUES ('AE', 1.05, 'AED', (select price_adjustment from markets where name = 'US'));
INSERT INTO markets (name, vat, currency, price_adjustment) VALUES ('SA', 1.05, 'USD', (select price_adjustment from markets where name = 'US'));

INSERT INTO market_locales (market_id, locale_id, name) VALUES
    ((SELECT id FROM markets WHERE name = 'AE'), (SELECT id FROM locales WHERE value = 'en_AE'), 'United Arab Emirates'),
    ((SELECT id FROM markets WHERE name = 'SA'), (SELECT id FROM locales WHERE value = 'en_SA'), 'Saudi Arabia');

CREATE SEQUENCE "order-invoiceIdAE" start 1000;
CREATE SEQUENCE "order-invoiceIdSA" start 1000;

INSERT INTO product_blacklist (product_id, group_id, market_id)
    SELECT product_id, group_id, (select id from markets where name = 'AE')
    FROM product_blacklist WHERE market_id = (select id from markets where name = 'SE');
INSERT INTO product_blacklist (product_id, group_id, market_id)
    SELECT product_id, group_id, (select id from markets where name = 'SA')
    FROM product_blacklist WHERE market_id = (select id from markets where name = 'SE');

INSERT INTO collections_texts (collection_id, meta_title, meta_description, title, description, slug, locale_id)
    SELECT collection_id, meta_title, meta_description, title, description, slug, (SELECT id FROM locales WHERE value = 'en_AE')
    FROM collections_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO designer_texts (designerid, header, description, locale_id)
    SELECT designerid, header, description, (SELECT id FROM locales WHERE value = 'en_AE')
    FROM designer_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO categorydata (category_id, datakey_id, text, locale_id)
    SELECT category_id, datakey_id, text, (SELECT id FROM locales WHERE value = 'en_AE')
    FROM categorydata WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO category_texts (locale_id, category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description)
    SELECT (SELECT id FROM locales WHERE value = 'en_AE'), category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description
    FROM category_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');

INSERT INTO collections_texts (collection_id, meta_title, meta_description, title, description, slug, locale_id)
    SELECT collection_id, meta_title, meta_description, title, description, slug, (SELECT id FROM locales WHERE value = 'en_SA')
    FROM collections_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO designer_texts (designerid, header, description, locale_id)
    SELECT designerid, header, description, (SELECT id FROM locales WHERE value = 'en_SA')
    FROM designer_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO categorydata (category_id, datakey_id, text, locale_id)
    SELECT category_id, datakey_id, text, (SELECT id FROM locales WHERE value = 'en_SA')
    FROM categorydata WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO category_texts (locale_id, category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description)
    SELECT (SELECT id FROM locales WHERE value = 'en_SA'), category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description
    FROM category_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');

INSERT INTO category_texts_v2 (locale_id, category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description)
    SELECT (SELECT id FROM locales WHERE value = 'en_SA'), category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description
    FROM category_texts_v2 WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
INSERT INTO category_texts_v2 (locale_id, category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description)
    SELECT (SELECT id FROM locales WHERE value = 'en_AE'), category_id, wallpaper_name, wallpaper_h1, wallpaper_description, canvas_name, canvas_h1, canvas_description, name, design_wallpaper_h1, design_wallpaper_description, poster_name, poster_h1, poster_description, framed_print_name, framed_print_h1, framed_print_description
    FROM category_texts_v2 WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_GB');
