import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
  console.log('Seeding marketing outreach data...');

  // ── 6 Channel Buckets ──
  const x = await prisma.mktChannelBucket.upsert({
    where: { name: 'x' },
    update: {},
    create: {
      name: 'x',
      label: 'X (Twitter)',
      description: 'Primary social channel for sports picks, engagement, and brand building via the SportsClaw Twitter agent.',
      icon: 'x-twitter',
      color: '#000000',
      goals: 'Grow followers, drive engagement, build credibility, convert free users to paid.',
      tone: 'Confident but approachable. Data-driven. Never arrogant. Sports-savvy language.',
      sortOrder: 0,
    },
  });

  const facebook = await prisma.mktChannelBucket.upsert({
    where: { name: 'facebook' },
    update: {},
    create: {
      name: 'facebook',
      label: 'Facebook',
      description: 'Community building and longer-form content. Groups, pages, and ads.',
      icon: 'facebook',
      color: '#1877F2',
      goals: 'Build community groups, share recaps and educational content.',
      tone: 'Friendly, conversational, community-focused.',
      sortOrder: 1,
    },
  });

  const instagram = await prisma.mktChannelBucket.upsert({
    where: { name: 'instagram' },
    update: {},
    create: {
      name: 'instagram',
      label: 'Instagram',
      description: 'Visual-first content: infographics, stories, reels for sports picks and behind-the-scenes.',
      icon: 'instagram',
      color: '#E4405F',
      goals: 'Visual brand presence, reach younger audience, stories engagement.',
      tone: 'Visual, punchy captions, emoji-friendly, lifestyle-meets-sports.',
      sortOrder: 2,
    },
  });

  const tiktok = await prisma.mktChannelBucket.upsert({
    where: { name: 'tiktok' },
    update: {},
    create: {
      name: 'tiktok',
      label: 'TikTok',
      description: 'Short-form video content: quick picks, betting education, trending sports moments.',
      icon: 'tiktok',
      color: '#000000',
      goals: 'Viral reach, younger demo acquisition, brand awareness through entertainment.',
      tone: 'Casual, trendy, fast-paced, entertaining. Use trending sounds/formats.',
      sortOrder: 3,
    },
  });

  const email = await prisma.mktChannelBucket.upsert({
    where: { name: 'email' },
    update: {},
    create: {
      name: 'email',
      label: 'Email',
      description: 'Newsletter, drip campaigns, and transactional emails for user retention and conversion.',
      icon: 'email',
      color: '#6366F1',
      goals: 'Nurture leads, retain users, drive upgrades, deliver daily picks digest.',
      tone: 'Professional but warm. Personalized. Value-first, sell-second.',
      sortOrder: 4,
    },
  });

  const clients = await prisma.mktChannelBucket.upsert({
    where: { name: 'clients' },
    update: {},
    create: {
      name: 'clients',
      label: 'Clients',
      description: 'B2B client pipeline: partnerships, affiliates, sponsors, and enterprise leads.',
      icon: 'briefcase',
      color: '#10B981',
      goals: 'Close partnership deals, manage affiliate relationships, track sponsor pipeline.',
      tone: 'Professional, consultative, ROI-focused.',
      sortOrder: 5,
    },
  });

  // ── X Bucket: Content Pillars ──
  const pillars = await Promise.all([
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Education', color: '#3B82F6', sortOrder: 0,
        description: 'Teach followers about sports betting concepts, analytics, and strategy.',
        examples: JSON.parse('["Did you know line movement of 2+ points often signals sharp action?","Understanding CLV: why closing line value matters more than W/L record"]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Game Context', color: '#F59E0B', sortOrder: 1,
        description: 'Pre-game breakdowns, injury impacts, matchup analysis, and situational angles.',
        examples: JSON.parse('["Tonight\'s NBA slate: 3 games with significant injury news that moved lines","Back-to-back fatigue alert: Team X played last night and travels to Y"]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Product Value', color: '#10B981', sortOrder: 2,
        description: 'Showcase SportsClaw features, accuracy, and unique capabilities.',
        examples: JSON.parse('["Our model identified this line 4 hours before the market moved","SportsClaw users got this pick at -110. It closed at -135."]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Social Proof', color: '#8B5CF6', sortOrder: 3,
        description: 'Share wins, user testimonials, track record, and credibility builders.',
        examples: JSON.parse('["3-0 sweep last night. Our subscribers ate well.","User spotlight: @user has been with us since day 1"]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Community Prompts', color: '#EC4899', sortOrder: 4,
        description: 'Polls, questions, and engagement-driving content to build community.',
        examples: JSON.parse('["What\'s your best bet tonight? Drop your lock below","Poll: Most overrated team this season?"]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Partner/Affiliate', color: '#F97316', sortOrder: 5,
        description: 'Sportsbook promos, affiliate offers, and partner content.',
        examples: JSON.parse('["New user promo: Get $200 in bonus bets when you sign up through our link","Partner spotlight: Why we recommend BookX for prop bets"]'),
      },
    }),
    prisma.mktContentPillar.create({
      data: {
        bucketId: x.id, name: 'Brand/Story', color: '#06B6D4', sortOrder: 6,
        description: 'Behind-the-scenes, mission, team, and brand narrative content.',
        examples: JSON.parse('["Why we built SportsClaw: tired of capper culture, wanted data-first picks","Weekend update from the team: what we\'re working on next"]'),
      },
    }),
  ]);

  // ── X Bucket: Post Formats ──
  const formats = await Promise.all([
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Single Post', charLimit: 280, sortOrder: 0, description: 'Standard single tweet.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Image Post', charLimit: 280, sortOrder: 1, description: 'Tweet with attached image/infographic.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Thread', charLimit: 280, sortOrder: 2, description: 'Multi-tweet thread for deep dives.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Poll', charLimit: 280, sortOrder: 3, description: 'Engagement poll with 2-4 options.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Quote Tweet', charLimit: 280, sortOrder: 4, description: 'Quote tweet with commentary on external content.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Reply', charLimit: 280, sortOrder: 5, description: 'Reply to follower or trending tweet.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'DM Sequence', charLimit: 1000, sortOrder: 6, description: 'Direct message drip sequence.' } }),
    prisma.mktPostFormat.create({ data: { bucketId: x.id, name: 'Short Video', charLimit: 280, sortOrder: 7, description: 'Tweet with short video clip.' } }),
  ]);

  // ── X Bucket: CTAs ──
  await Promise.all([
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'Follow us for daily free picks', intensity: 'soft', sortOrder: 0 } }),
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'Like & RT if you tailed this pick', intensity: 'soft', sortOrder: 1 } }),
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'Check out today\'s full card on SportsClaw', url: 'https://sportsclaw.guru', intensity: 'medium', sortOrder: 2 } }),
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'Try SportsClaw free — link in bio', url: 'https://sportsclaw.guru', intensity: 'medium', sortOrder: 3 } }),
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'Upgrade to Pro for full model access', url: 'https://sportsclaw.guru/pricing', intensity: 'hard', sortOrder: 4 } }),
    prisma.mktCta.create({ data: { bucketId: x.id, label: 'DM us "PICKS" for today\'s premium plays', intensity: 'hard', sortOrder: 5 } }),
  ]);

  // ── X Bucket: Default Schedule Slots (2/day) ──
  const slotTimes = [
    { day: 1, time: '10:00', label: 'Mon Morning — Education/Context' },
    { day: 1, time: '19:00', label: 'Mon Evening — Game Picks' },
    { day: 2, time: '10:00', label: 'Tue Morning — Education/Context' },
    { day: 2, time: '19:00', label: 'Tue Evening — Game Picks' },
    { day: 3, time: '10:00', label: 'Wed Morning — Education/Context' },
    { day: 3, time: '19:00', label: 'Wed Evening — Game Picks' },
    { day: 4, time: '10:00', label: 'Thu Morning — Education/Context' },
    { day: 4, time: '19:00', label: 'Thu Evening — Game Picks' },
    { day: 5, time: '10:00', label: 'Fri Morning — Education/Context' },
    { day: 5, time: '19:00', label: 'Fri Evening — Game Picks' },
    { day: 6, time: '11:00', label: 'Sat Morning — Weekend Slate Preview' },
    { day: 6, time: '18:00', label: 'Sat Evening — Game Picks' },
    { day: 0, time: '11:00', label: 'Sun Morning — Weekend Slate Preview' },
    { day: 0, time: '18:00', label: 'Sun Evening — Game Picks' },
  ];

  for (const s of slotTimes) {
    await prisma.mktScheduleSlot.create({
      data: { bucketId: x.id, dayOfWeek: s.day, time: s.time, label: s.label },
    });
  }

  // ── Clients Bucket: Sample Leads ──
  await Promise.all([
    prisma.mktClientLead.create({
      data: {
        bucketId: clients.id, name: 'BetPlatform Inc', company: 'BetPlatform',
        email: 'partnerships@betplatform.example', source: 'inbound',
        stage: 'qualified', value: 5000, notes: 'Interested in affiliate partnership. Had intro call.',
      },
    }),
    prisma.mktClientLead.create({
      data: {
        bucketId: clients.id, name: 'SportsPodcast Network', company: 'SPN Media',
        email: 'ads@spn.example', source: 'outreach',
        stage: 'contacted', value: 2000, notes: 'Sent sponsorship proposal for weekly segment.',
      },
    }),
    prisma.mktClientLead.create({
      data: {
        bucketId: clients.id, name: 'DataVendor Co', company: 'DataVendor',
        email: 'sales@datavendor.example', source: 'referral',
        stage: 'lead', value: 10000, notes: 'Potential data licensing deal. Need to schedule discovery call.',
      },
    }),
  ]);

  console.log('Seed complete!');
  console.log(`  Buckets: ${[x, facebook, instagram, tiktok, email, clients].map(b => b.label).join(', ')}`);
  console.log(`  X pillars: ${pillars.length}`);
  console.log(`  X formats: ${formats.length}`);
  console.log(`  X schedule slots: ${slotTimes.length}`);
}

main()
  .catch((e) => { console.error(e); process.exit(1); })
  .finally(() => prisma.$disconnect());
