import { describe, expect, it } from 'bun:test';
import { resolveStatementMetricTargetField } from './statementMetricTargetFields';

describe('resolveStatementMetricTargetField', () => {
  it('resolves representative /em metric keys', () => {
    expect(resolveStatementMetricTargetField('totalRevenues')).toBe(
      'total_revenues',
    );
    expect(resolveStatementMetricTargetField('grossProfit')).toBe(
      'gross_profit',
    );
    expect(resolveStatementMetricTargetField('basicEps')).toBe('basic_eps');
    expect(resolveStatementMetricTargetField('totalSharesOutstanding')).toBe(
      'total_shares_outstanding',
    );
  });

  it('resolves existing /fa shorthand aliases', () => {
    expect(resolveStatementMetricTargetField('cash')).toBe(
      'cash_and_equivalents',
    );
    expect(resolveStatementMetricTargetField('assets')).toBe('total_assets');
    expect(resolveStatementMetricTargetField('liabilities')).toBe(
      'total_liabilities',
    );
    expect(resolveStatementMetricTargetField('equity')).toBe('total_equity');
    expect(resolveStatementMetricTargetField('shares')).toBe(
      'total_shares_outstanding',
    );
  });

  it('resolves missing /bs aliases', () => {
    expect(resolveStatementMetricTargetField('shortTermInvestments')).toBe(
      'short_term_investments',
    );
    expect(resolveStatementMetricTargetField('totalCurrentAssets')).toBe(
      'total_current_assets',
    );
    expect(resolveStatementMetricTargetField('totalAssets')).toBe(
      'total_assets',
    );
    expect(
      resolveStatementMetricTargetField(
        'accruedExpensesAndOtherCurrentLiabilities',
      ),
    ).toBe('accrued_expenses_and_other_current_liabilities');
    expect(resolveStatementMetricTargetField('totalCurrentLiabilities')).toBe(
      'total_current_liabilities',
    );
    expect(resolveStatementMetricTargetField('totalLiabilities')).toBe(
      'total_liabilities',
    );
    expect(resolveStatementMetricTargetField('retainedEarnings')).toBe(
      'retained_earnings',
    );
    expect(resolveStatementMetricTargetField('totalEquity')).toBe(
      'total_equity',
    );
    expect(resolveStatementMetricTargetField('sharesOutstanding')).toBe(
      'total_shares_outstanding',
    );
  });

  it('returns null for unknown metric keys', () => {
    expect(resolveStatementMetricTargetField('unknownMetric')).toBeNull();
  });
});
