import { DataSource } from 'typeorm';

export async function seedLegalPages(dataSource: DataSource) {
  const legalPagesRepo = dataSource.getRepository('legal_pages');
  const legalPageVersionsRepo = dataSource.getRepository('legal_page_versions');

  // Get admin user (demo admin)
  const usersRepo = dataSource.getRepository('users');
  const adminUser = await usersRepo.findOne({
    where: { email: 'demo@parentflowapp.com' },
  });

  const adminUserId = adminUser?.id || null;

  const legalPages = [
    {
      slug: 'privacy',
      title: 'Privacy Policy',
      language: 'en',
      content: `# Privacy Policy

## 1. Introduction

Welcome to ParentFlow ("we," "our," or "us"). We are committed to protecting your privacy and the privacy of your children. This Privacy Policy explains how we collect, use, disclose, and safeguard your information when you use our mobile application and related services (collectively, the "Service").

Because our Service is designed for parents and caregivers tracking information about children aged 0-6 years, we take extra precautions to comply with the Children's Online Privacy Protection Act (COPPA) and the General Data Protection Regulation (GDPR).

## 2. Information We Collect

### 2.1 Personal Information You Provide

- **Account Information:** Name, email address, date of birth (for COPPA age verification)
- **Profile Information:** Profile photo, timezone, language preferences
- **Child Information:** Child's name, date of birth, gender, photo (optional)
- **Activity Data:** Feeding times, sleep schedules, diaper changes, medication records, milestones
- **AI Chat Messages:** Questions and conversations with our AI assistant
- **Photos and Media:** Photos of children and milestones (optional)

### 2.2 Automatically Collected Information

- **Device Information:** Device type, operating system, unique device identifiers
- **Usage Data:** App features used, session duration, error logs
- **Technical Data:** IP address, browser type, time zone settings

## 3. How We Use Your Information

We use the collected information for:

- Providing and maintaining the Service
- Tracking your child's activities and patterns
- Generating insights and analytics about your child's development
- Providing AI-powered parenting support and answers
- Syncing data across family members' devices
- Sending notifications and reminders
- Improving our Service and developing new features
- Detecting and preventing fraud and security issues
- Complying with legal obligations

## 4. Children's Privacy (COPPA Compliance)

Our Service is designed for parents and caregivers to track information about their children. We do not knowingly collect personal information directly from children under 13 years of age.

**Parental Rights:**

- Review your child's information
- Request deletion of your child's information
- Refuse further collection or use of your child's information
- Export your child's data in a portable format

To exercise these rights, please contact us at **hello@parentflow.com**.

## 5. Data Sharing and Disclosure

**We do NOT sell your personal information or your child's information.**

We may share information with:

- **Family Members:** Data is shared with family members you invite to your family group
- **Service Providers:** Cloud hosting (AWS/Azure), analytics (anonymized), customer support
- **AI Providers:** OpenAI or Anthropic (for AI chat, with no PII in training data)
- **Legal Compliance:** When required by law or to protect rights and safety

## 6. Data Security

We implement industry-standard security measures to protect your information:

- End-to-end encryption for sensitive child data
- Secure HTTPS connections for all communications
- Regular security audits and penetration testing
- Access controls and authentication mechanisms
- Encrypted database storage

## 7. Your Rights (GDPR Compliance)

Under GDPR, you have the following rights:

- **Right to Access:** Request a copy of your personal data
- **Right to Rectification:** Correct inaccurate information
- **Right to Erasure:** Request deletion of your data ("right to be forgotten")
- **Right to Data Portability:** Export your data in a machine-readable format
- **Right to Restrict Processing:** Limit how we use your data
- **Right to Object:** Opt-out of certain data processing
- **Right to Withdraw Consent:** Revoke consent at any time

To exercise your rights, visit Settings → Privacy → Data Rights or email **hello@parentflow.com**.

## 8. Contact Us

If you have questions about this Privacy Policy or our data practices, please contact us:

**Email:** hello@parentflow.com
**Address:** Serbota 3, Bucharest, Romania`,
      isPublished: true,
    },
    {
      slug: 'terms',
      title: 'Terms of Service',
      language: 'en',
      content: `# Terms of Service

## 1. Acceptance of Terms

By accessing or using ParentFlow (the "Service"), you agree to be bound by these Terms of Service ("Terms"). If you do not agree to these Terms, do not use the Service.

These Terms constitute a legally binding agreement between you and ParentFlow ("we," "us," or "our").

## 2. Description of Service

ParentFlow is a parenting organization and tracking application designed to help parents and caregivers manage childcare for children aged 0-6 years. The Service includes:

- Activity tracking (feeding, sleep, diapers, medicine, milestones)
- AI-powered parenting support and guidance
- Family synchronization and collaboration tools
- Analytics and insights about your child's patterns
- Voice input capabilities
- Photo storage and milestone tracking

## 3. User Accounts

### 3.1 Account Creation

To use the Service, you must create an account. You agree to:

- Provide accurate and complete information
- Maintain the security of your account credentials
- Notify us immediately of any unauthorized access
- Be responsible for all activities under your account

### 3.2 Age Requirements

You must be at least 18 years old (or the age of majority in your jurisdiction) to create an account. Users between 13-17 years old may only use the Service with parental consent.

## 4. Acceptable Use

You agree NOT to:

- Use the Service for any illegal purpose
- Violate any laws or regulations
- Infringe on intellectual property rights
- Upload malicious code or viruses
- Attempt to gain unauthorized access to our systems
- Harass, abuse, or harm other users
- Share inappropriate content involving minors
- Use automated tools to access the Service (bots, scrapers)
- Reverse engineer or decompile the Service

## 5. Medical Disclaimer

**THE SERVICE IS NOT A SUBSTITUTE FOR PROFESSIONAL MEDICAL ADVICE.**

Our AI assistant and tracking features provide general information and insights only. They do not constitute medical advice, diagnosis, or treatment. Always consult with qualified healthcare professionals for medical concerns.

**In case of emergency, call your local emergency services immediately.**

## 6. Intellectual Property

The Service, including its design, features, code, and content (excluding user content), is owned by ParentFlow and protected by copyright, trademark, and other intellectual property laws.

You may not copy, modify, distribute, sell, or create derivative works based on the Service without our written permission.

## 7. Termination

### 7.1 Termination by You

You may terminate your account at any time through the app settings. Upon termination, your data will be deleted in accordance with our Privacy Policy.

### 7.2 Termination by Us

We reserve the right to suspend or terminate your account if you violate these Terms or engage in harmful behavior. We will provide notice where reasonably possible.

## 8. Disclaimers

**THE SERVICE IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTIES OF ANY KIND.**

We disclaim all warranties, express or implied, including warranties of merchantability, fitness for a particular purpose, and non-infringement. We do not guarantee that the Service will be error-free, secure, or uninterrupted.

## 9. Limitation of Liability

TO THE MAXIMUM EXTENT PERMITTED BY LAW, WE SHALL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES ARISING FROM YOUR USE OF THE SERVICE.

Our total liability shall not exceed the amount you paid us in the 12 months preceding the claim, or $100, whichever is greater.

## 10. Contact Us

If you have questions about these Terms, please contact us:

**Email:** hello@parentflow.com
**Address:** Serbota 3, Bucharest, Romania`,
      isPublished: true,
    },
    {
      slug: 'eula',
      title: 'End User License Agreement (EULA)',
      language: 'en',
      content: `# End User License Agreement (EULA)

**Last Updated:** October 8, 2025

## 1. Agreement to Terms

This End User License Agreement ("EULA") is a legal agreement between you and ParentFlow for the use of the ParentFlow mobile application and related services (the "Application").

By installing, accessing, or using the Application, you agree to be bound by the terms of this EULA.

## 2. License Grant

Subject to your compliance with this EULA, ParentFlow grants you a limited, non-exclusive, non-transferable, revocable license to:

- Download, install, and use the Application on devices you own or control
- Access and use the Application's features and services

## 3. License Restrictions

You may NOT:

- Copy, modify, or create derivative works of the Application
- Reverse engineer, decompile, or disassemble the Application
- Remove, alter, or obscure any copyright, trademark, or other proprietary notices
- Rent, lease, lend, sell, redistribute, or sublicense the Application
- Use the Application for any unlawful purpose
- Interfere with or disrupt the Application or servers
- Attempt to gain unauthorized access to any part of the Application

## 4. Intellectual Property

The Application and all rights, including intellectual property rights, are owned by ParentFlow. This EULA does not grant you any rights to ParentFlow's trademarks, service marks, or logos.

## 5. User Content

You retain ownership of content you create or upload through the Application. By using the Application, you grant ParentFlow a license to use, store, and process your content to provide the services.

## 6. Privacy

Your use of the Application is subject to ParentFlow's Privacy Policy. Please review our Privacy Policy to understand how we collect, use, and protect your information.

## 7. Updates and Modifications

ParentFlow may provide updates, patches, or modifications to the Application. These updates may be automatically downloaded and installed. You agree to receive such updates as part of your use of the Application.

## 8. Termination

This EULA is effective until terminated. Your rights under this EULA will terminate automatically if you fail to comply with any of its terms. Upon termination, you must cease all use of the Application and delete all copies.

## 9. Disclaimer of Warranties

THE APPLICATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. PARENTFLOW DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.

## 10. Limitation of Liability

TO THE MAXIMUM EXTENT PERMITTED BY LAW, PARENTFLOW SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING FROM YOUR USE OF THE APPLICATION, INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES.

## 11. Governing Law

This EULA shall be governed by and construed in accordance with the laws of Romania, without regard to its conflict of law provisions.

## 12. Contact Information

If you have any questions about this EULA, please contact us:

**Email:** hello@parentflow.com
**Address:** Serbota 3, Bucharest, Romania`,
      isPublished: true,
    },
    {
      slug: 'cookies',
      title: 'Cookie Policy',
      language: 'en',
      content: `# Cookie Policy

**Last Updated:** October 8, 2025

## 1. Introduction

This Cookie Policy explains how ParentFlow ("we," "us," or "our") uses cookies and similar technologies when you use our website and mobile application (the "Service").

## 2. What Are Cookies?

Cookies are small text files stored on your device (computer, smartphone, or tablet) when you visit a website or use an application. They help us provide you with a better experience by remembering your preferences and improving our Service.

## 3. Types of Cookies We Use

### 3.1 Essential Cookies

These cookies are necessary for the Service to function properly. They enable core functionality such as security, authentication, and accessibility.

- **Session cookies:** Maintain your login session
- **Security cookies:** Protect against unauthorized access
- **Authentication cookies:** Verify your identity

### 3.2 Performance Cookies

These cookies help us understand how you use the Service, allowing us to improve its performance and functionality.

- **Analytics cookies:** Track usage patterns and feature adoption
- **Error tracking cookies:** Help us identify and fix technical issues

### 3.3 Functional Cookies

These cookies remember your preferences and choices to provide a personalized experience.

- **Language preference cookies**
- **Theme/appearance cookies**
- **Timezone cookies**

### 3.4 Advertising Cookies

We do not currently use advertising cookies. If this changes in the future, we will update this policy and obtain your consent where required.

## 4. How We Use Cookies

We use cookies for the following purposes:

- **Authentication:** Keep you logged in between sessions
- **Security:** Protect your account from unauthorized access
- **Preferences:** Remember your language, timezone, and other settings
- **Analytics:** Understand how you use our Service to make improvements
- **Performance:** Optimize load times and functionality
- **Error tracking:** Identify and resolve technical issues

## 5. Third-Party Cookies

We may use third-party services that set cookies on your device:

- **Analytics providers:** Google Analytics (anonymized)
- **Cloud services:** AWS, Azure
- **Error tracking:** Sentry

These third parties have their own privacy policies governing their use of cookies.

## 6. Managing Cookies

You can control and manage cookies in several ways:

### 6.1 Browser Settings

Most web browsers allow you to:

- View and delete existing cookies
- Block third-party cookies
- Block all cookies (note: this may affect Service functionality)
- Clear cookies when you close your browser

### 6.2 Mobile App Settings

In our mobile app, you can manage cookie-like preferences through:

- App Settings → Privacy → Cookie Preferences
- Device Settings → Apps → ParentFlow → Permissions

### 6.3 Opt-Out Tools

You can opt out of analytics tracking:

- Google Analytics: [https://tools.google.com/dlpage/gaoptout](https://tools.google.com/dlpage/gaoptout)

## 7. Do Not Track Signals

Some browsers include a "Do Not Track" (DNT) feature. Currently, there is no industry standard for how to respond to DNT signals. We do not currently respond to DNT signals, but we will update this policy if standards are established.

## 8. Cookie Duration

- **Session cookies:** Deleted when you close your browser/app
- **Persistent cookies:** Remain until expiration date or manual deletion
- **Our persistent cookies typically last:** 1 year

## 9. Changes to This Cookie Policy

We may update this Cookie Policy from time to time. We will notify you of significant changes by email or through the Service. Your continued use after changes constitutes acceptance of the updated policy.

## 10. Contact Us

If you have questions about our use of cookies, please contact us:

**Email:** hello@parentflow.com
**Address:** Serbota 3, Bucharest, Romania`,
      isPublished: true,
    },
  ];

  console.log('Seeding legal pages...');

  for (const pageData of legalPages) {
    // Check if already exists
    const existing = await legalPagesRepo.findOne({
      where: { slug: pageData.slug, language: pageData.language },
    });

    if (existing) {
      console.log(`Legal page "${pageData.slug}" (${pageData.language}) already exists, skipping...`);
      continue;
    }

    // Insert legal page
    const insertResult = await legalPagesRepo.insert({
      slug: pageData.slug,
      title: pageData.title,
      content: pageData.content,
      language: pageData.language,
      version: 1,
      is_published: pageData.isPublished,
      last_updated_by: adminUserId,
      created_at: new Date(),
      updated_at: new Date(),
    });

    const pageId = insertResult.identifiers[0].id;

    // Insert initial version
    await legalPageVersionsRepo.insert({
      legal_page_id: pageId,
      version: 1,
      title: pageData.title,
      content: pageData.content,
      created_by: adminUserId,
      created_at: new Date(),
    });

    console.log(`✓ Created legal page: "${pageData.title}" (${pageData.slug})`);
  }

  console.log('Legal pages seeding completed!');
}
