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

import { RECOMMENDATION_TYPE_COUNT } from '@/config/plan-limits';

import { generalFaqs, pricingFaqs } from './faqs';

describe('generalFaqs', () => {
  it('includes the OpenAI bundled AI question', () => {
    const q = generalFaqs.find((f) => f.question === 'Do I need an OpenAI API key?');
    expect(q).toBeDefined();
    expect(q?.answer).toMatch(/bundled/i);
    expect(q?.answer).toMatch(/No\./);
    expect(q?.answer).toMatch(/5\/month/);
    expect(q?.answer).toMatch(/30/);
    expect(q?.answer).toMatch(/200/);
  });

  it('includes the Ahrefs/Semrush complement question', () => {
    const q = generalFaqs.find((f) =>
      f.question.toLowerCase().includes('replace ahrefs'),
    );
    expect(q).toBeDefined();
    expect(q?.answer).toMatch(/complement/i);
    // Ensures the answer frames RankWiz as a complement, not a replacement
    expect(q?.answer).not.toMatch(/replace/i);
  });

  it('includes the how quickly will I see results question', () => {
    const q = generalFaqs.find((f) =>
      f.question.toLowerCase().includes('how quickly'),
    );
    expect(q).toBeDefined();
    expect(q?.answer).toMatch(/10 minutes/i);
  });

  it('includes at least 8 FAQs', () => {
    expect(generalFaqs.length).toBeGreaterThanOrEqual(8);
  });

  it('every FAQ has non-empty question and answer', () => {
    for (const faq of generalFaqs) {
      expect(faq.question.trim().length).toBeGreaterThan(0);
      expect(faq.answer.trim().length).toBeGreaterThan(0);
    }
  });

  it('recommendation type count in free-plan FAQ matches RECOMMENDATION_TYPE_COUNT constant', () => {
    const faq = generalFaqs.find((f) => f.question.toLowerCase().includes('free plan'));
    expect(faq).toBeDefined();
    expect(faq?.answer).toContain(`${RECOMMENDATION_TYPE_COUNT} recommendation types`);
  });
});

describe('pricingFaqs', () => {
  it('recommendation type count in pricing FAQ matches RECOMMENDATION_TYPE_COUNT constant', () => {
    const faq = pricingFaqs.find((f) => f.question.toLowerCase().includes("what's included"));
    expect(faq).toBeDefined();
    expect(faq?.answer).toContain(`${RECOMMENDATION_TYPE_COUNT} recommendation types`);
  });
});
