// Example Vitest spec. Proves the toolchain runs and demonstrates the
// Zod + schema-inferred type pattern. Run with: npm test
import { describe, it, expect } from 'vitest';
import {
  LoginRequestSchema,
  ExtensionCreateSchema,
  PeNarrativeRequestSchema,
} from './schemas';

describe('LoginRequestSchema', () => {
  it('accepts a valid login body', () => {
    const ok = LoginRequestSchema.safeParse({
      email: 'danvics@ped-ai.test',
      password: 'some-password',
    });
    expect(ok.success).toBe(true);
  });

  it('rejects an invalid email', () => {
    const bad = LoginRequestSchema.safeParse({
      email: 'not-an-email',
      password: 'x',
    });
    expect(bad.success).toBe(false);
  });

  it('rejects missing password', () => {
    const bad = LoginRequestSchema.safeParse({ email: 'a@b.com' });
    expect(bad.success).toBe(false);
  });
});

describe('ExtensionCreateSchema', () => {
  it('accepts a minimal extension', () => {
    const ok = ExtensionCreateSchema.safeParse({
      location: 'Main Hospital',
      name: 'Nursery',
      number: '5866',
    });
    expect(ok.success).toBe(true);
  });

  it('defaults type when omitted (Zod returns the field as undefined)', () => {
    const ok = ExtensionCreateSchema.safeParse({
      location: 'X',
      name: 'Y',
      number: '1',
    });
    expect(ok.success).toBe(true);
    if (ok.success) expect(ok.data.type).toBeUndefined();
  });

  it('rejects missing required fields', () => {
    const bad = ExtensionCreateSchema.safeParse({ location: 'X' });
    expect(bad.success).toBe(false);
  });
});

describe('PeNarrativeRequestSchema', () => {
  it('requires a non-empty steps array', () => {
    const bad = PeNarrativeRequestSchema.safeParse({ steps: [] });
    expect(bad.success).toBe(false);
  });

  it('accepts a single step', () => {
    const ok = PeNarrativeRequestSchema.safeParse({
      steps: [{ label: 'General appearance', status: 'normal' }],
    });
    expect(ok.success).toBe(true);
  });
});
