/**
 * Unit tests for usage module — types + validation.
 */

import { describe, it, expect } from 'vitest';
import { UpsertUsageSchema, CheckLimitsSchema } from './types.js';

describe('UpsertUsageSchema', () => {
  it('accepts valid usage record', () => {
    const result = UpsertUsageSchema.safeParse({
      userId: 'user_123',
      date: '2026-02-10',
      dictations: 5,
      words: 250,
      tokensUsed: 1200,
      costUsd: 0.01,
    });
    expect(result.success).toBe(true);
  });

  it('accepts with model', () => {
    const result = UpsertUsageSchema.safeParse({
      userId: 'user_123',
      date: '2026-02-10',
      model: 'gpt-4o',
    });
    expect(result.success).toBe(true);
  });

  it('rejects invalid date format', () => {
    const result = UpsertUsageSchema.safeParse({
      userId: 'user_123',
      date: '2026/02/10',
    });
    expect(result.success).toBe(false);
  });

  it('rejects missing userId', () => {
    const result = UpsertUsageSchema.safeParse({
      date: '2026-02-10',
    });
    expect(result.success).toBe(false);
  });

  it('rejects negative values', () => {
    const result = UpsertUsageSchema.safeParse({
      userId: 'user_123',
      date: '2026-02-10',
      tokensUsed: -100,
    });
    expect(result.success).toBe(false);
  });
});

describe('CheckLimitsSchema', () => {
  it('accepts valid input', () => {
    const result = CheckLimitsSchema.safeParse({
      userId: 'user_123',
      plan: 'pro',
    });
    expect(result.success).toBe(true);
  });

  it('rejects invalid plan', () => {
    const result = CheckLimitsSchema.safeParse({
      userId: 'user_123',
      plan: 'premium',
    });
    expect(result.success).toBe(false);
  });
});
