// Feature: client-portal, Property 7: CLP formatting correctness
// **Validates: Requirements 16.1, 16.2, 16.3**

import { describe, it, expect } from 'vitest';
import * as fc from 'fast-check';
import { formatCLP } from '@/lib/utils/format';

describe('Property 7: CLP formatting correctness', () => {
  it('for any number, formatCLP(n) produces a string containing "CLP"', () => {
    fc.assert(
      fc.property(
        fc.double({ min: -1e15, max: 1e15, noNaN: true, noDefaultInfinity: true }),
        (n) => {
          const result = formatCLP(n);
          expect(result).toContain('CLP');
        },
      ),
      { numRuns: 100 },
    );
  });

  it('for any negative number, the output starts with "-"', () => {
    fc.assert(
      fc.property(
        fc.double({ min: -1e15, max: Math.fround(-0.01), noNaN: true, noDefaultInfinity: true }),
        (n) => {
          const result = formatCLP(n);
          expect(result).toMatch(/^-/);
        },
      ),
      { numRuns: 100 },
    );
  });

  it('for any number with absolute value >= 1,000,000, the output contains "M"', () => {
    fc.assert(
      fc.property(
        fc.oneof(
          fc.double({ min: 1_000_000, max: 1e15, noNaN: true, noDefaultInfinity: true }),
          fc.double({ min: -1e15, max: -1_000_000, noNaN: true, noDefaultInfinity: true }),
        ),
        (n) => {
          const result = formatCLP(n);
          expect(result).toContain('M');
        },
      ),
      { numRuns: 100 },
    );
  });
});
