import { describe, it, expect } from 'vitest';
import fs from 'fs';
import path from 'path';

describe('README Validation - Phase 9.5', () => {
  it('Test 1: README.md exists in root', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    expect(fs.existsSync(readmePath)).toBe(true);
  });

  it('Test 2: README.md contains # Quasar heading', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/^# Quasar/m);
  });

  it('Test 3: README.md contains Features section', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/## Features/);
  });

  it('Test 4: README.md contains Quick Start section', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/## Quick Start/);
  });

  it('Test 5: README.md contains Installation subsection', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/### Installation/);
  });

  it('Test 6: README.md contains Testing section', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/## Testing/);
  });

  it('Test 7: README.md contains link to SECURITY.md', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/\[SECURITY\.md\]\(SECURITY\.md\)/);
  });

  it('Test 8: README.md contains link to docs/API_KEYS.md', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/\[docs\/API_KEYS\.md\]\(docs\/API_KEYS\.md\)/) ||
      expect(content).toMatch(/docs\/API_KEYS\.md/);
  });

  it('Test 9: README.md contains Project Structure section', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/## Project Structure/);
  });

  it('Test 10: README.md contains folder tree with backend/frontend', () => {
    const readmePath = path.join(__dirname, '..', 'README.md');
    const content = fs.readFileSync(readmePath, 'utf-8');
    expect(content).toMatch(/backend/);
    expect(content).toMatch(/frontend/);
    expect(content).toMatch(/tests/);
  });

  it('Test 11: frontend/README.md exists', () => {
    const frontendReadmePath = path.join(__dirname, '..', 'frontend', 'README.md');
    expect(fs.existsSync(frontendReadmePath)).toBe(true);
  });

  it('Test 12: frontend/README.md contains Setup instructions', () => {
    const frontendReadmePath = path.join(__dirname, '..', 'frontend', 'README.md');
    const content = fs.readFileSync(frontendReadmePath, 'utf-8');
    expect(content).toMatch(/## Setup/) || expect(content).toMatch(/setup/i);
  });
});
