const db = require("./config/database");

async function updatePagesWithContent() {
  try {
    // About Page Content
    const aboutContent = `
      <h2>Our Story</h2>
      <p>Sky Art Shop specializes in scrapbooking, journaling, cardmaking, and collaging stationery. We are passionate about helping people express their creativity and preserve their memories.</p>
      <p>Our mission is to promote mental health and wellness through creative art activities. We believe that crafting is more than just a hobby—it's a therapeutic journey that brings joy, mindfulness, and self-expression.</p>

      <h2>What We Offer</h2>
      <p>Our carefully curated collection includes:</p>
      <ul>
        <li>Washi tape in various designs and patterns</li>
        <li>Unique stickers for journaling and scrapbooking</li>
        <li>High-quality journals and notebooks</li>
        <li>Card making supplies and kits</li>
        <li>Collage materials and ephemera</li>
        <li>Creative tools and accessories</li>
      </ul>

      <h2>Why Choose Us</h2>
      <p>We hand-select every item in our store to ensure the highest quality and uniqueness. Whether you're a seasoned crafter or just starting your creative journey, we have something special for everyone.</p>
      <p>Join our community of creative minds and let your imagination soar!</p>
    `;

    const aboutDelta = {
      ops: [
        { insert: "Our Story", attributes: { header: 2 } },
        {
          insert:
            "\nSky Art Shop specializes in scrapbooking, journaling, cardmaking, and collaging stationery. We are passionate about helping people express their creativity and preserve their memories.\n\nOur mission is to promote mental health and wellness through creative art activities. We believe that crafting is more than just a hobby—it's a therapeutic journey that brings joy, mindfulness, and self-expression.\n\n",
        },
        { insert: "What We Offer", attributes: { header: 2 } },
        { insert: "\nOur carefully curated collection includes:\n" },
        {
          insert: "Washi tape in various designs and patterns",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Unique stickers for journaling and scrapbooking",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "High-quality journals and notebooks",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Card making supplies and kits",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Collage materials and ephemera",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Creative tools and accessories",
          attributes: { list: "bullet" },
        },
        { insert: "\n\n" },
        { insert: "Why Choose Us", attributes: { header: 2 } },
        {
          insert:
            "\nWe hand-select every item in our store to ensure the highest quality and uniqueness. Whether you're a seasoned crafter or just starting your creative journey, we have something special for everyone.\n\nJoin our community of creative minds and let your imagination soar!\n",
        },
      ],
    };

    // Contact Page Content
    const contactContent = `
      <h2>Get In Touch</h2>
      <p>Have questions or feedback? We'd love to hear from you. Send us a message and we'll respond as soon as possible.</p>
      
      <h2>Contact Information</h2>
      <h3>Phone</h3>
      <p>Give us a call: <strong><a href="tel:+1234567890">+1 (234) 567-8900</a></strong></p>
      
      <h3>Email</h3>
      <p>Send us an email: <strong><a href="mailto:support@skyartshop.com">support@skyartshop.com</a></strong></p>
      
      <h3>Location</h3>
      <p><strong>123 Creative Street<br>Art District, CA 90210</strong></p>
      
      <h2>Business Hours</h2>
      <ul>
        <li><strong>Monday - Friday:</strong> 9:00 AM - 6:00 PM</li>
        <li><strong>Saturday:</strong> 10:00 AM - 4:00 PM</li>
        <li><strong>Sunday:</strong> Closed</li>
      </ul>
      
      <p><em>Fill out the contact form on our website and we'll get back to you within 24 hours</em></p>
    `;

    const contactDelta = {
      ops: [
        { insert: "Get In Touch", attributes: { header: 2 } },
        {
          insert:
            "\nHave questions or feedback? We'd love to hear from you. Send us a message and we'll respond as soon as possible.\n\n",
        },
        { insert: "Contact Information", attributes: { header: 2 } },
        { insert: "\n" },
        { insert: "Phone", attributes: { header: 3 } },
        { insert: "\nGive us a call: " },
        {
          insert: "+1 (234) 567-8900",
          attributes: { bold: true, link: "tel:+1234567890" },
        },
        { insert: "\n\n" },
        { insert: "Email", attributes: { header: 3 } },
        { insert: "\nSend us an email: " },
        {
          insert: "support@skyartshop.com",
          attributes: { bold: true, link: "mailto:support@skyartshop.com" },
        },
        { insert: "\n\n" },
        { insert: "Location", attributes: { header: 3 } },
        { insert: "\n" },
        {
          insert: "123 Creative Street\nArt District, CA 90210",
          attributes: { bold: true },
        },
        { insert: "\n\n" },
        { insert: "Business Hours", attributes: { header: 2 } },
        { insert: "\n" },
        {
          insert: "Monday - Friday: 9:00 AM - 6:00 PM",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Saturday: 10:00 AM - 4:00 PM",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        { insert: "Sunday: Closed", attributes: { list: "bullet" } },
        {
          insert:
            "\n\nFill out the contact form on our website and we'll get back to you within 24 hours\n",
        },
      ],
    };

    // Privacy Page Content
    const privacyContent = `
      <h2>Privacy Policy</h2>
      <p><em>Last Updated: December 23, 2025</em></p>
      
      <h3>1. Information We Collect</h3>
      <p>We collect information you provide directly to us, including:</p>
      <ul>
        <li>Name and contact information</li>
        <li>Billing and shipping addresses</li>
        <li>Payment information</li>
        <li>Order history and preferences</li>
        <li>Communications with us</li>
      </ul>
      
      <h3>2. How We Use Your Information</h3>
      <p>We use the information we collect to:</p>
      <ul>
        <li>Process and fulfill your orders</li>
        <li>Communicate with you about products and services</li>
        <li>Improve our website and customer experience</li>
        <li>Send marketing communications (with your consent)</li>
        <li>Comply with legal obligations</li>
      </ul>
      
      <h3>3. Information Sharing</h3>
      <p>We do not sell or rent your personal information to third parties. We may share your information with:</p>
      <ul>
        <li>Service providers who assist in our operations</li>
        <li>Payment processors for transaction processing</li>
        <li>Shipping companies for order delivery</li>
      </ul>
      
      <h3>4. Data Security</h3>
      <p>We implement appropriate security measures to protect your personal information. However, no method of transmission over the Internet is 100% secure.</p>
      
      <h3>5. Your Rights</h3>
      <p>You have the right to:</p>
      <ul>
        <li>Access your personal information</li>
        <li>Correct inaccurate data</li>
        <li>Request deletion of your data</li>
        <li>Opt-out of marketing communications</li>
      </ul>
      
      <h3>6. Contact Us</h3>
      <p>If you have questions about this Privacy Policy, please contact us at: <strong><a href="mailto:privacy@skyartshop.com">privacy@skyartshop.com</a></strong></p>
    `;

    const privacyDelta = {
      ops: [
        { insert: "Privacy Policy", attributes: { header: 2 } },
        { insert: "\n" },
        {
          insert: "Last Updated: December 23, 2025",
          attributes: { italic: true },
        },
        { insert: "\n\n" },
        { insert: "1. Information We Collect", attributes: { header: 3 } },
        {
          insert:
            "\nWe collect information you provide directly to us, including:\n",
        },
        {
          insert: "Name and contact information",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Billing and shipping addresses",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        { insert: "Payment information", attributes: { list: "bullet" } },
        { insert: "\n" },
        {
          insert: "Order history and preferences",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        { insert: "Communications with us", attributes: { list: "bullet" } },
        { insert: "\n\n" },
        { insert: "2. How We Use Your Information", attributes: { header: 3 } },
        { insert: "\nWe use the information we collect to:\n" },
        {
          insert: "Process and fulfill your orders",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Communicate with you about products and services",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Improve our website and customer experience",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Send marketing communications (with your consent)",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Comply with legal obligations",
          attributes: { list: "bullet" },
        },
        { insert: "\n\n" },
        { insert: "3. Information Sharing", attributes: { header: 3 } },
        {
          insert:
            "\nWe do not sell or rent your personal information to third parties. We may share your information with:\n",
        },
        {
          insert: "Service providers who assist in our operations",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Payment processors for transaction processing",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Shipping companies for order delivery",
          attributes: { list: "bullet" },
        },
        { insert: "\n\n" },
        { insert: "4. Data Security", attributes: { header: 3 } },
        {
          insert:
            "\nWe implement appropriate security measures to protect your personal information. However, no method of transmission over the Internet is 100% secure.\n\n",
        },
        { insert: "5. Your Rights", attributes: { header: 3 } },
        { insert: "\nYou have the right to:\n" },
        {
          insert: "Access your personal information",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        { insert: "Correct inaccurate data", attributes: { list: "bullet" } },
        { insert: "\n" },
        {
          insert: "Request deletion of your data",
          attributes: { list: "bullet" },
        },
        { insert: "\n" },
        {
          insert: "Opt-out of marketing communications",
          attributes: { list: "bullet" },
        },
        { insert: "\n\n" },
        { insert: "6. Contact Us", attributes: { header: 3 } },
        {
          insert:
            "\nIf you have questions about this Privacy Policy, please contact us at: ",
        },
        {
          insert: "privacy@skyartshop.com",
          attributes: { bold: true, link: "mailto:privacy@skyartshop.com" },
        },
        { insert: "\n" },
      ],
    };

    // Update About page
    await db.query(
      `UPDATE pages SET 
        content = $1, 
        pagecontent = $2, 
        metatitle = $3, 
        metadescription = $4,
        updatedat = NOW()
      WHERE slug = 'about'`,
      [
        JSON.stringify(aboutDelta),
        aboutContent,
        "About Us - Sky Art Shop",
        "Learn about Sky Art Shop, our mission to promote wellness through creative activities, and our carefully curated collection of scrapbooking and journaling supplies.",
      ]
    );
    console.log("✓ About page updated");

    // Update Contact page
    await db.query(
      `UPDATE pages SET 
        content = $1, 
        pagecontent = $2, 
        metatitle = $3, 
        metadescription = $4,
        updatedat = NOW()
      WHERE slug = 'contact'`,
      [
        JSON.stringify(contactDelta),
        contactContent,
        "Contact Us - Sky Art Shop",
        "Get in touch with Sky Art Shop. Phone: +1 (234) 567-8900 | Email: support@skyartshop.com | Open Monday-Saturday",
      ]
    );
    console.log("✓ Contact page updated");

    // Update Privacy page
    await db.query(
      `UPDATE pages SET 
        content = $1, 
        pagecontent = $2, 
        metatitle = $3, 
        metadescription = $4,
        updatedat = NOW()
      WHERE slug = 'privacy'`,
      [
        JSON.stringify(privacyDelta),
        privacyContent,
        "Privacy Policy - Sky Art Shop",
        "Read our privacy policy to understand how Sky Art Shop collects, uses, and protects your personal information.",
      ]
    );
    console.log("✓ Privacy page updated");

    console.log("\n✅ All pages updated successfully!");
    process.exit(0);
  } catch (error) {
    console.error("❌ Error updating pages:", error);
    process.exit(1);
  }
}

updatePagesWithContent();
