-- Add New Zealand

INSERT INTO locales (value, name) VALUES ('ja_JP', 'Japanese');

INSERT INTO markets (name, vat, currency, price_adjustment) VALUES ('JP', 1, '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 = 'JP'), (SELECT id FROM locales WHERE value = 'ja_JP'), 'Japan');

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 = 'ja_JP')
    FROM collections_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_US');

INSERT INTO designer_texts (designerid, header, description, locale_id)
    SELECT designerid, header, description, (SELECT id FROM locales WHERE value = 'ja_JP')
    FROM designer_texts WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_US');

INSERT INTO categorydata (category_id, datakey_id, text, locale_id)
    SELECT category_id, datakey_id, text, (SELECT id FROM locales WHERE value = 'ja_JP')
    FROM categorydata WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_US');

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 = 'ja_JP'), 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_US');

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

INSERT INTO "delivery-methods_prices" (territory, currency, option, option_value, price, method) VALUES
	('JP', 'USD', '', '', 29, (select id from "delivery-methods" where name = 'fedexStandardWorld')),
	('JP', 'USD', '', '', 36, (select id from "delivery-methods" where name = 'fedexExpressWorld'));

CREATE SEQUENCE "order-invoiceIdJP" start 1000;

INSERT INTO "i18n-texts_data" (textid, text, locale_id)
    SELECT textid, text, (select id from locales where value = 'ja_JP')
    FROM "i18n-texts_data" WHERE locale_id = (SELECT id FROM locales WHERE value = 'en_US');
