-- 2026-04-16
-- Seed de demonstracao do modulo de publicidade
-- Objetivo:
-- - criar campanhas de exemplo para visualizar a central admin
-- - publicar ao menos uma campanha gratuita para aparecer nas paginas publicas
-- - deixar uma campanha paga pronta para validar o fluxo comercial no admin

START TRANSACTION;

INSERT INTO wpjy_ads_campaigns
  (id_contrato, title, description, advertiser_name, advertiser_type, advertiser_id, pricing_model, price, status, creative_type, image_url, mobile_image_url, html_content, target_url, cta_label, badge_text, start_at, end_at, targeting_json, created_by)
SELECT
  0,
  'Campanha demo gratuita do perfil profissional',
  'Peca de demonstracao para validar a exibicao do anuncio no topo do perfil profissional.',
  'Clinica Demo',
  'empresa',
  NULL,
  'free',
  0.00,
  'active',
  'image',
  'https://images.unsplash.com/photo-1576091160399-112ba8d25d1f?auto=format&fit=crop&w=1400&q=80',
  'https://images.unsplash.com/photo-1576091160399-112ba8d25d1f?auto=format&fit=crop&w=900&q=80',
  NULL,
  'https://example.com/demo-publicidade-profissional',
  'Conhecer agora',
  'Patrocinado',
  NOW() - INTERVAL 2 DAY,
  NOW() + INTERVAL 30 DAY,
  JSON_OBJECT(),
  NULL
WHERE NOT EXISTS (
  SELECT 1 FROM wpjy_ads_campaigns WHERE title = 'Campanha demo gratuita do perfil profissional'
);

INSERT INTO wpjy_ads_campaigns
  (id_contrato, title, description, advertiser_name, advertiser_type, advertiser_id, pricing_model, price, status, creative_type, image_url, mobile_image_url, html_content, target_url, cta_label, badge_text, start_at, end_at, targeting_json, created_by)
SELECT
  0,
  'Campanha demo gratuita do meu perfil',
  'Peca de demonstracao para validar a exibicao do anuncio no topo do meu perfil do cliente.',
  'Laboratorio Demo',
  'empresa',
  NULL,
  'free',
  0.00,
  'active',
  'image',
  'https://images.unsplash.com/photo-1584515933487-779824d29309?auto=format&fit=crop&w=1400&q=80',
  'https://images.unsplash.com/photo-1584515933487-779824d29309?auto=format&fit=crop&w=900&q=80',
  NULL,
  'https://example.com/demo-publicidade-cliente',
  'Ver beneficios',
  'Oferta',
  NOW() - INTERVAL 2 DAY,
  NOW() + INTERVAL 30 DAY,
  JSON_OBJECT(),
  NULL
WHERE NOT EXISTS (
  SELECT 1 FROM wpjy_ads_campaigns WHERE title = 'Campanha demo gratuita do meu perfil'
);

INSERT INTO wpjy_ads_campaigns
  (id_contrato, title, description, advertiser_name, advertiser_type, advertiser_id, pricing_model, price, status, creative_type, image_url, mobile_image_url, html_content, target_url, cta_label, badge_text, start_at, end_at, targeting_json, created_by)
SELECT
  0,
  'Campanha demo paga para fluxo comercial',
  'Campanha de exemplo para validar cadastro, precificacao e gatilho de cobranca dentro da central admin.',
  'Parceiro Premium Demo',
  'empresa',
  NULL,
  'paid',
  490.00,
  'active',
  'image',
  'https://images.unsplash.com/photo-1516549655169-df83a0774514?auto=format&fit=crop&w=1400&q=80',
  'https://images.unsplash.com/photo-1516549655169-df83a0774514?auto=format&fit=crop&w=900&q=80',
  NULL,
  'https://example.com/demo-publicidade-premium',
  'Solicitar agora',
  'Premium',
  NOW() - INTERVAL 1 DAY,
  NOW() + INTERVAL 20 DAY,
  JSON_OBJECT(),
  NULL
WHERE NOT EXISTS (
  SELECT 1 FROM wpjy_ads_campaigns WHERE title = 'Campanha demo paga para fluxo comercial'
);

INSERT INTO wpjy_ads_campaign_slots (campaign_id, slot_id, sort_order, weight)
SELECT c.id, s.id, 0, 1
  FROM wpjy_ads_campaigns c
  JOIN wpjy_ads_slots s ON s.code = 'cliente.profissional_perfil.topo' AND s.id_contrato = 0
 WHERE c.title = 'Campanha demo gratuita do perfil profissional'
   AND NOT EXISTS (
     SELECT 1 FROM wpjy_ads_campaign_slots cs WHERE cs.campaign_id = c.id AND cs.slot_id = s.id
   );

INSERT INTO wpjy_ads_campaign_slots (campaign_id, slot_id, sort_order, weight)
SELECT c.id, s.id, 0, 1
  FROM wpjy_ads_campaigns c
  JOIN wpjy_ads_slots s ON s.code = 'cliente.meu_perfil.topo' AND s.id_contrato = 0
 WHERE c.title = 'Campanha demo gratuita do meu perfil'
   AND NOT EXISTS (
     SELECT 1 FROM wpjy_ads_campaign_slots cs WHERE cs.campaign_id = c.id AND cs.slot_id = s.id
   );

INSERT INTO wpjy_ads_campaign_slots (campaign_id, slot_id, sort_order, weight)
SELECT c.id, s.id, 0, 1
  FROM wpjy_ads_campaigns c
  JOIN wpjy_ads_slots s ON s.code = 'cliente.perfil_cliente.topo' AND s.id_contrato = 0
 WHERE c.title = 'Campanha demo gratuita do meu perfil'
   AND NOT EXISTS (
     SELECT 1 FROM wpjy_ads_campaign_slots cs WHERE cs.campaign_id = c.id AND cs.slot_id = s.id
   );

INSERT INTO wpjy_ads_campaign_slots (campaign_id, slot_id, sort_order, weight)
SELECT c.id, s.id, 1, 1
  FROM wpjy_ads_campaigns c
  JOIN wpjy_ads_slots s ON s.code = 'cliente.profissional_perfil.topo' AND s.id_contrato = 0
 WHERE c.title = 'Campanha demo paga para fluxo comercial'
   AND NOT EXISTS (
     SELECT 1 FROM wpjy_ads_campaign_slots cs WHERE cs.campaign_id = c.id AND cs.slot_id = s.id
   );

COMMIT;
