/**
 * Referral Campaign Email and SMS Templates
 * Used for marketing automation and user acquisition
 */

export const referralCampaigns = {
  // Welcome email with referral code
  welcomeWithReferral: {
    subject: "Welcome to CoinKrazy! Here's Your Referral Code",
    htmlTemplate: `
      <h1>Welcome to CoinKrazy! 🎰</h1>
      <p>Thanks for joining our community of players!</p>
      
      <h2>Earn 500 SC by Referring Friends</h2>
      <p>Share your unique referral code and earn <strong>500 Sweepstakes Coins</strong> for each friend who joins:</p>
      
      <div style="background: #f0f0f0; padding: 20px; border-radius: 8px; margin: 20px 0;">
        <p style="font-size: 12px; color: #666;">Your Referral Code:</p>
        <p style="font-size: 24px; font-weight: bold; font-family: monospace;">{{referralCode}}</p>
        <p style="font-size: 12px; color: #666;">Share this code with friends or use this link:</p>
        <p><a href="{{referralLink}}" style="color: #ff9900;">{{referralLink}}</a></p>
      </div>
      
      <h3>How It Works:</h3>
      <ul>
        <li>Share your code with friends</li>
        <li>They sign up and enter your code</li>
        <li>You both get 500 SC bonus!</li>
        <li>Earn unlimited - no cap on referrals</li>
      </ul>
      
      <p>Start playing now and earn rewards!</p>
    `,
    smsTemplate: "Welcome to CoinKrazy! 🎰 Earn 500 SC for each friend you refer. Your code: {{referralCode}} Share: {{referralLink}}",
  },

  // Referral reminder email
  referralReminder: {
    subject: "Earn 500 SC - Share Your CoinKrazy Referral Code",
    htmlTemplate: `
      <h1>Earn Extra Coins! 💰</h1>
      <p>Hi {{playerName}},</p>
      
      <p>Did you know you can earn <strong>500 Sweepstakes Coins</strong> for each friend who joins CoinKrazy?</p>
      
      <div style="background: #fff3cd; padding: 20px; border-radius: 8px; margin: 20px 0; border-left: 4px solid #ff9900;">
        <p style="margin: 0; font-weight: bold;">Your Referral Code: <span style="font-family: monospace;">{{referralCode}}</span></p>
      </div>
      
      <h3>Share With:</h3>
      <ul>
        <li>Friends and family</li>
        <li>Social media</li>
        <li>Gaming communities</li>
        <li>Anyone who loves slots!</li>
      </ul>
      
      <p><a href="{{referralLink}}" style="background: #ff9900; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">Share Your Code</a></p>
    `,
    smsTemplate: "Earn 500 SC! Share your CoinKrazy referral code {{referralCode}} with friends. {{referralLink}}",
  },

  // Referral success notification
  referralSuccess: {
    subject: "🎉 Your Friend Joined! You Earned 500 SC",
    htmlTemplate: `
      <h1>Congratulations! 🎉</h1>
      <p>Your friend <strong>{{friendName}}</strong> just joined CoinKrazy using your referral code!</p>
      
      <div style="background: #d4edda; padding: 20px; border-radius: 8px; margin: 20px 0; border-left: 4px solid #28a745;">
        <p style="margin: 0; font-size: 20px; font-weight: bold; color: #28a745;">+500 SC Credited to Your Account</p>
      </div>
      
      <p>Your referral bonus has been added to your account. Keep sharing to earn more!</p>
      
      <h3>Your Referral Stats:</h3>
      <ul>
        <li>Total Referrals: {{totalReferrals}}</li>
        <li>Total Earned: {{totalEarned}} SC</li>
        <li>Referral Rank: {{referralRank}}</li>
      </ul>
      
      <p><a href="{{dashboardLink}}" style="background: #ff9900; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">View Your Referrals</a></p>
    `,
    smsTemplate: "🎉 {{friendName}} joined! You earned 500 SC. Total referrals: {{totalReferrals}}. Share more: {{referralLink}}",
  },

  // Leaderboard notification
  leaderboardNotification: {
    subject: "You're in the Top {{position}} Referrers! 🏆",
    htmlTemplate: `
      <h1>You're a Top Referrer! 🏆</h1>
      <p>Congratulations! You've climbed to <strong>#{{position}}</strong> on the CoinKrazy referral leaderboard!</p>
      
      <div style="background: #e7f3ff; padding: 20px; border-radius: 8px; margin: 20px 0; border-left: 4px solid #0066cc;">
        <p style="margin: 0; font-size: 18px; font-weight: bold;">{{totalReferrals}} Referrals | {{totalEarned}} SC Earned</p>
      </div>
      
      <h3>Top Referrers Get Special Perks:</h3>
      <ul>
        <li>Exclusive cosmetics and badges</li>
        <li>VIP status and bonuses</li>
        <li>Early access to new games</li>
        <li>Monthly referrer rewards</li>
      </ul>
      
      <p>Keep referring to stay on top!</p>
      <p><a href="{{leaderboardLink}}" style="background: #ff9900; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">View Leaderboard</a></p>
    `,
    smsTemplate: "🏆 You're #{{position}} on the referral leaderboard! {{totalReferrals}} referrals, {{totalEarned}} SC earned.",
  },

  // Friend invitation email
  friendInvitation: {
    subject: "{{senderName}} Invited You to CoinKrazy - Get 500 SC!",
    htmlTemplate: `
      <h1>You're Invited! 🎮</h1>
      <p><strong>{{senderName}}</strong> thinks you'd love CoinKrazy and invited you to join!</p>
      
      <div style="background: #f0f0f0; padding: 20px; border-radius: 8px; margin: 20px 0;">
        <p style="font-size: 16px; font-weight: bold;">Join Now and Get:</p>
        <ul style="font-size: 16px;">
          <li>5,000 Gold Coins to start</li>
          <li>10 Sweepstakes Coins</li>
          <li>500 SC bonus from {{senderName}}'s referral</li>
        </ul>
      </div>
      
      <p style="text-align: center; margin: 30px 0;">
        <a href="{{signupLink}}" style="background: #ff9900; color: white; padding: 16px 32px; text-decoration: none; border-radius: 4px; display: inline-block; font-size: 18px; font-weight: bold;">Join CoinKrazy Now</a>
      </p>
      
      <p style="text-align: center; color: #666; font-size: 12px;">
        Use code <strong>{{referralCode}}</strong> during signup to claim your bonus
      </p>
    `,
    smsTemplate: "{{senderName}} invited you to CoinKrazy! Get 500 SC + 5000 GC. Join: {{signupLink}} Code: {{referralCode}}",
  },

  // Re-engagement campaign
  reengagement: {
    subject: "Come Back to CoinKrazy - Claim Your 1,000 SC Welcome Back Bonus",
    htmlTemplate: `
      <h1>We Miss You! 👋</h1>
      <p>It's been a while since you played CoinKrazy. We've added new games and features you'll love!</p>
      
      <div style="background: #fff3cd; padding: 20px; border-radius: 8px; margin: 20px 0; border-left: 4px solid #ff9900;">
        <p style="margin: 0; font-weight: bold;">Welcome Back Bonus: 1,000 SC</p>
        <p style="margin: 5px 0 0 0; font-size: 12px; color: #666;">Valid for 7 days</p>
      </div>
      
      <h3>What's New:</h3>
      <ul>
        <li>{{newGamesCount}} new games added</li>
        <li>Seasonal tournaments with {{prizePool}} prize pools</li>
        <li>Enhanced daily bonuses (up to 15,000 GC)</li>
        <li>New VIP tier rewards</li>
      </ul>
      
      <p><a href="{{loginLink}}" style="background: #ff9900; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">Log In & Claim Bonus</a></p>
    `,
    smsTemplate: "Welcome back! Claim 1,000 SC bonus. {{newGamesCount}} new games + tournaments. {{loginLink}}",
  },
};

export const campaignSchedules = {
  // Welcome sequence (sent to new players)
  welcomeSequence: [
    {
      delay: "0h", // Immediately
      template: "welcomeWithReferral",
      channels: ["email", "sms"],
    },
    {
      delay: "24h", // 1 day later
      template: "referralReminder",
      channels: ["email"],
    },
    {
      delay: "72h", // 3 days later
      template: "referralReminder",
      channels: ["sms"],
    },
  ],

  // Referral engagement (sent to active referrers)
  referralEngagement: [
    {
      delay: "7d", // Weekly
      template: "referralReminder",
      channels: ["email"],
      condition: "hasReferralCode && totalReferrals < 5",
    },
    {
      delay: "0h", // Immediately when friend joins
      template: "referralSuccess",
      channels: ["email", "sms"],
      condition: "newReferralJoined",
    },
    {
      delay: "0h", // Immediately when reaching leaderboard
      template: "leaderboardNotification",
      channels: ["email"],
      condition: "enteredLeaderboard",
    },
  ],

  // Re-engagement (sent to inactive players)
  reengagement: [
    {
      delay: "14d", // 2 weeks after last activity
      template: "reengagement",
      channels: ["email"],
      condition: "lastActivityOlderThan(14d)",
    },
    {
      delay: "30d", // 30 days after last activity
      template: "reengagement",
      channels: ["sms"],
      condition: "lastActivityOlderThan(30d)",
    },
  ],
};

export const campaignMetrics = {
  // Track campaign performance
  trackOpen: async (campaignId: string, userId: number) => {
    // Log email open
    console.log(`Campaign ${campaignId} opened by user ${userId}`);
  },

  trackClick: async (campaignId: string, userId: number, linkId: string) => {
    // Log link click
    console.log(`Campaign ${campaignId} link ${linkId} clicked by user ${userId}`);
  },

  trackConversion: async (campaignId: string, userId: number) => {
    // Log conversion (referral, deposit, etc)
    console.log(`Campaign ${campaignId} converted for user ${userId}`);
  },

  trackUnsubscribe: async (campaignId: string, userId: number) => {
    // Log unsubscribe
    console.log(`User ${userId} unsubscribed from campaign ${campaignId}`);
  },
};
