INSERT INTO networks (id, code, name, retrocession_rate, status) VALUES
(1, 'network-alpha', 'Réseau Alpha', 5.0000, 'active');

INSERT INTO shops (id, network_id, code, name, slug, status, is_generic, primary_color, secondary_color, retrocession_rate) VALUES
(1, NULL, 'generic', 'Boutique Générique', 'generic', 'active', 1, '#1f2937', '#6366f1', NULL),
(2, 1, 'franchise-a', 'Franchise A', 'franchise-a', 'active', 0, '#0f766e', '#14b8a6', 5.0000);

INSERT INTO shop_domains (shop_id, host, is_primary, is_active) VALUES
(1, 'generic.localhost', 1, 1),
(2, 'franchise-a.localhost', 1, 1);

INSERT INTO modules (id, code, name) VALUES
(1, 'catalog', 'Catalogue'),
(2, 'pricing', 'Tarification'),
(3, 'orders', 'Commandes'),
(4, 'credits', 'Crédits'),
(5, 'retrocessions', 'Rétrocessions');

INSERT INTO shop_modules (shop_id, module_id, enabled) VALUES
(1, 1, 1),
(1, 2, 1),
(2, 1, 1),
(2, 2, 1),
(2, 4, 1),
(2, 5, 1);

INSERT INTO addresses (user_id, type, label, company, line1, postal_code, city, country, is_default) VALUES
(1, 'billing', 'Facturation', 'Imprimerie Centrale', '1 rue de Paris', '75001', 'Paris', 'FR', 1),
(2, 'shipping', 'Livraison', 'Franchise A', '8 avenue du Commerce', '69001', 'Lyon', 'FR', 1);

INSERT INTO roles (id, code, name) VALUES
(1, 'master_admin', 'Administrateur maître'),
(2, 'shop_manager', 'Gestionnaire boutique');

INSERT INTO permissions (id, code, name) VALUES
(1, 'shops.manage', 'Gérer les boutiques'),
(2, 'catalog.manage', 'Gérer le catalogue'),
(3, 'pricing.manage', 'Gérer la tarification');

INSERT INTO role_permissions (role_id, permission_id) VALUES
(1, 1), (1, 2), (1, 3),
(2, 2);

INSERT INTO user_shop_memberships (user_id, shop_id, role_code, is_active) VALUES
(1, 1, 'master_admin', 1),
(1, 2, 'master_admin', 1),
(2, 2, 'shop_manager', 1);

INSERT INTO products (id, sku, default_name, default_description, product_type, category_name, subcategory_name, base_spec_json, is_active) VALUES
(
    1,
    'PAP-FLYERS',
    'Flyers',
    'Support de diffusion de masse.',
    'flyers',
    'Papeterie',
    'Prospectus',
    JSON_OBJECT(
        'notes', 'Support de diffusion de masse',
        'source', 'seed-demo',
        'examples', JSON_ARRAY('A6', 'A5', 'A4', 'A3', 'DL')
    ),
    1
),
(
    2,
    'SIG-ROLLUP',
    'Roll-up',
    'Support signalétique enrouleur.',
    'rollup',
    'Signalétique',
    'Kakemono autoportant',
    JSON_OBJECT(
        'notes', 'Très standard en salon',
        'source', 'seed-demo'
    ),
    1
),
(
    3,
    'GOD-MUG',
    'Mug personnalisé',
    'Mug céramique personnalisable.',
    'mug',
    'Goodies',
    'Objet pub',
    JSON_OBJECT(
        'capacity', '330ml',
        'source', 'seed-demo'
    ),
    1
);

INSERT INTO product_assets (product_id, asset_type, asset_role, path, position) VALUES
(1, 'image', 'cover', '/assets/products/flyers.jpg', 1),
(2, 'image', 'cover', '/assets/products/rollup.jpg', 1),
(3, 'image', 'cover', '/assets/products/mug.jpg', 1);

INSERT INTO product_attributes (id, product_id, code, name, input_type, is_required, is_pricing_quantity, position) VALUES
(1, 1, 'format', 'Format', 'select', 1, 0, 10),
(2, 1, 'support_matiere', 'Support / matière', 'select', 0, 0, 20),
(3, 1, 'grammage_epaisseur', 'Grammage / épaisseur', 'select', 0, 0, 30),
(4, 1, 'impression', 'Impression', 'select', 0, 0, 40),
(5, 1, 'finition', 'Finition', 'select', 0, 0, 50),
(6, 1, 'faconnage_option', 'Façonnage / option', 'select', 0, 0, 60),
(7, 1, 'quantite_du_lot', 'Quantité du lot', 'select', 1, 1, 70),
(8, 2, 'format', 'Format', 'select', 1, 0, 10),
(9, 2, 'support_matiere', 'Support / matière', 'select', 0, 0, 20),
(10, 2, 'grammage_epaisseur', 'Grammage / épaisseur', 'select', 0, 0, 30),
(11, 2, 'impression', 'Impression', 'select', 0, 0, 40),
(12, 2, 'finition', 'Finition', 'select', 0, 0, 50),
(13, 2, 'faconnage_option', 'Façonnage / option', 'select', 0, 0, 60),
(14, 2, 'quantite_du_lot', 'Quantité du lot', 'select', 1, 1, 70),
(15, 3, 'contenance', 'Contenance', 'select', 1, 0, 10),
(16, 3, 'marquage', 'Marquage', 'select', 0, 0, 20),
(17, 3, 'quantite_du_lot', 'Quantité du lot', 'select', 1, 1, 30);

INSERT INTO product_attribute_options (product_attribute_id, value, label, position) VALUES
(1, 'A6', 'A6', 10),
(1, 'A5', 'A5', 20),
(1, 'A4', 'A4', 30),
(1, 'A3', 'A3', 40),
(1, 'DL', 'DL', 50),
(1, 'carré', 'carré', 60),
(1, 'sur mesure', 'sur mesure', 70),
(2, 'Couché mat', 'Couché mat', 10),
(2, 'couché brillant', 'couché brillant', 20),
(2, 'offset', 'offset', 30),
(2, 'recyclé', 'recyclé', 40),
(2, 'création', 'création', 50),
(3, '90g', '90g', 10),
(3, '115g', '115g', 20),
(3, '135g', '135g', 30),
(3, '170g', '170g', 40),
(3, '250g', '250g', 50),
(3, '300g', '300g', 60),
(3, '350g', '350g', 70),
(4, 'Quadri recto', 'Quadri recto', 10),
(4, 'quadri recto/verso', 'quadri recto/verso', 20),
(4, 'noir', 'noir', 30),
(5, 'Aucune', 'Aucune', 10),
(5, 'vernis sélectif', 'vernis sélectif', 20),
(5, 'pelliculage mat', 'pelliculage mat', 30),
(5, 'brillant', 'brillant', 40),
(5, 'Soft Touch', 'Soft Touch', 50),
(6, 'Sans', 'Sans', 10),
(6, 'Coins arrondis', 'Coins arrondis', 20),
(6, 'perforation', 'perforation', 30),
(6, 'numérotation', 'numérotation', 40),
(6, 'données variables', 'données variables', 50),
(7, '100', '100', 10),
(7, '250', '250', 20),
(7, '500', '500', 30),
(7, '1000', '1000', 40),
(7, '2500', '2500', 50),
(7, '5000', '5000', 60),
(7, '10000', '10000', 70),
(8, '85x200', '85x200', 10),
(8, '100x200', '100x200', 20),
(8, '120x200', '120x200', 30),
(8, '150x200', '150x200', 40),
(9, 'PVC', 'PVC', 10),
(9, 'polyester', 'polyester', 20),
(9, 'bâche', 'bâche', 30),
(9, 'tissu', 'tissu', 40),
(10, '440g', '440g', 10),
(10, '510g', '510g', 20),
(10, '610g', '610g', 30),
(11, 'Quadri recto', 'Quadri recto', 10),
(11, 'parfois recto/verso', 'parfois recto/verso', 20),
(12, 'Sans', 'Sans', 10),
(12, 'Lamination', 'Lamination', 20),
(12, 'anti-UV', 'anti-UV', 30),
(13, 'Sans', 'Sans', 10),
(13, 'Structure standard', 'Structure standard', 20),
(13, 'premium', 'premium', 30),
(13, 'double face', 'double face', 40),
(13, 'sac de transport', 'sac de transport', 50),
(14, '1', '1', 10),
(14, '2', '2', 20),
(14, '5', '5', 30),
(14, '10', '10', 40),
(14, '25', '25', 50),
(15, '330ml', '330ml', 10),
(15, '450ml', '450ml', 20),
(16, 'Sérigraphie', 'Sérigraphie', 10),
(16, 'Sublimation', 'Sublimation', 20),
(17, '12', '12', 10),
(17, '24', '24', 20),
(17, '48', '48', 30),
(17, '96', '96', 40);

INSERT INTO shop_products (id, shop_id, source_product_id, item_type, is_active, is_visible, override_name, override_description) VALUES
(1, 1, 1, 'activation', 1, 1, NULL, NULL),
(2, 1, 2, 'activation', 1, 1, NULL, NULL),
(3, 2, 1, 'activation', 1, 1, 'Flyers Réseau Alpha', 'Version publiée pour le réseau Alpha.'),
(4, 2, 1, 'derived', 1, 1, 'Flyers Promo Été', 'Déclinaison marketing locale pour campagne été.'),
(5, 2, 2, 'activation', 1, 1, NULL, NULL),
(6, 1, 3, 'activation', 1, 1, 'Mug personnalisé', 'Version standard boutique générique.');

INSERT INTO shop_product_assets (shop_product_id, asset_type, asset_role, path, position) VALUES
(4, 'image', 'cover', '/assets/shop/franchise-a/flyer-promo-ete.jpg', 1);

INSERT INTO price_grids (id, product_id, code, name, currency, is_active) VALUES
(1, 1, 'default', 'Tarif standard flyers', 'EUR', 1),
(2, 2, 'default', 'Tarif standard roll-up', 'EUR', 1),
(3, 3, 'default', 'Tarif standard mugs', 'EUR', 1);

INSERT INTO price_grid_rows (price_grid_id, criteria_key, criteria_json, min_qty, max_qty, nominal_price_ht, cost_price_ht) VALUES
(1, 'format:A5', JSON_OBJECT('format', 'A5'), 100, 499, 0.30, 0.20),
(1, 'format:A5', JSON_OBJECT('format', 'A5'), 500, NULL, 0.18, 0.12),
(1, 'format:A4', JSON_OBJECT('format', 'A4'), 100, 499, 0.42, 0.28),
(1, 'format:A4', JSON_OBJECT('format', 'A4'), 500, NULL, 0.26, 0.17),
(1, 'format:DL', JSON_OBJECT('format', 'DL'), 100, 499, 0.27, 0.18),
(1, 'format:DL', JSON_OBJECT('format', 'DL'), 500, NULL, 0.16, 0.11),
(2, 'format:85x200', JSON_OBJECT('format', '85x200'), 1, 4, 55.00, 37.00),
(2, 'format:85x200', JSON_OBJECT('format', '85x200'), 5, NULL, 48.00, 32.00),
(2, 'format:100x200', JSON_OBJECT('format', '100x200'), 1, 4, 68.00, 46.00),
(2, 'format:100x200', JSON_OBJECT('format', '100x200'), 5, NULL, 59.00, 40.00),
(3, 'default', JSON_OBJECT(), 12, 47, 4.80, 3.10),
(3, 'default', JSON_OBJECT(), 48, NULL, 4.10, 2.70);

INSERT INTO price_policies (scope_type, scope_id, coefficient, rounding_mode, priority) VALUES
('global', NULL, 1.5000, 'cent', 100),
('network', 1, 1.3000, 'cent', 200),
('shop', 2, 1.2500, 'cent', 300);

INSERT INTO credit_accounts (id, owner_type, owner_id, currency, balance_cached) VALUES
(1, 'shop', 2, 'EUR', 250.00);

INSERT INTO credit_transactions (account_id, movement_type, amount, reference, reason) VALUES
(1, 'grant', 250.00, 'INIT-2026-001', 'Crédit commercial initial');

INSERT INTO retrocession_policies (scope_type, scope_id, rate_percent, calculation_base, periodicity) VALUES
('network', 1, 5.0000, 'order_total_ht', 'monthly');
