-- 11: Seeds reglas por defecto (WHERE mc.id = 13). Edita el id si aplica.
SET NAMES utf8mb4;

INSERT INTO `ocr_customer_match_rule` (`maincompany_id`, `name`, `pattern`, `source_field`, `priority`, `enabled`, `created_at`, `updated_at`)
SELECT mc.id, 'Locker then full name', '{locker} {fullName}', 'recipient', 10, 1, NOW(), NOW()
FROM `maincompany` mc
WHERE mc.id = 13
  AND NOT EXISTS (
    SELECT 1 FROM `ocr_customer_match_rule` r WHERE r.maincompany_id = mc.id AND r.pattern = '{locker} {fullName}'
  );

INSERT INTO `ocr_customer_match_rule` (`maincompany_id`, `name`, `pattern`, `source_field`, `priority`, `enabled`, `created_at`, `updated_at`)
SELECT mc.id, 'Full name then locker', '{fullName} {locker}', 'recipient', 20, 1, NOW(), NOW()
FROM `maincompany` mc
WHERE mc.id = 13
  AND NOT EXISTS (
    SELECT 1 FROM `ocr_customer_match_rule` r WHERE r.maincompany_id = mc.id AND r.pattern = '{fullName} {locker}'
  );

INSERT INTO `ocr_customer_match_rule` (`maincompany_id`, `name`, `pattern`, `source_field`, `priority`, `enabled`, `created_at`, `updated_at`)
SELECT mc.id, 'Agency full name shipping type', '{agency} {fullName} {shippingType}', 'recipient', 30, 1, NOW(), NOW()
FROM `maincompany` mc
WHERE mc.id = 13
  AND NOT EXISTS (
    SELECT 1 FROM `ocr_customer_match_rule` r WHERE r.maincompany_id = mc.id AND r.pattern = '{agency} {fullName} {shippingType}'
  );

INSERT INTO `ocr_customer_match_rule` (`maincompany_id`, `name`, `pattern`, `source_field`, `priority`, `enabled`, `created_at`, `updated_at`)
SELECT mc.id, 'Shipping type full name agency', '{shippingType} {fullName} {agency}', 'recipient', 40, 1, NOW(), NOW()
FROM `maincompany` mc
WHERE mc.id = 13
  AND NOT EXISTS (
    SELECT 1 FROM `ocr_customer_match_rule` r WHERE r.maincompany_id = mc.id AND r.pattern = '{shippingType} {fullName} {agency}'
  );
