import type { TargetField } from '../types/mappings';

const STATEMENT_METRIC_TARGET_FIELDS: Record<string, TargetField> = {
  totalRevenues: 'total_revenues',
  costOfSales: 'cost_of_sales',
  grossProfit: 'gross_profit',
  sellingGeneralAndAdministrativeExpenses:
    'selling_general_and_administrative',
  researchAndDevelopmentExpenses: 'research_and_development',
  otherOperatingExpenses: 'other_operating_expenses',
  operatingProfit: 'operating_profit',
  consolidatedNetIncome: 'net_income',
  netIncomeAttributableToCommonShareholders:
    'net_income_attributable_to_common_shareholders',
  nonOperatingIncome: 'non_operating_income',
  totalNonOperatingIncome: 'total_non_operating_income',
  incomeBeforeProvisionForIncomeTaxes:
    'income_before_provision_for_income_taxes',
  provisionForIncomeTaxes: 'provision_for_income_taxes',
  basicEps: 'basic_eps',
  dilutedEps: 'diluted_eps',
  basicWeightedAverageSharesOutstanding:
    'basic_weighted_average_shares_outstanding',
  totalSharesOutstanding: 'total_shares_outstanding',
  dilutedWeightedAverageSharesOutstanding:
    'diluted_weighted_average_shares_outstanding',
  ebitda: 'ebitda',
  effectiveTaxRate: 'effective_tax_rate',
  cash: 'cash_and_equivalents',
  shortTermInvestments: 'short_term_investments',
  accountsReceivableNet: 'accounts_receivable_net',
  inventory: 'inventory',
  otherCurrentAssets: 'other_current_assets',
  totalCurrentAssets: 'total_current_assets',
  propertyPlantAndEquipmentNet: 'property_plant_and_equipment_net',
  goodwill: 'goodwill',
  intangibleAssets: 'intangible_assets',
  otherNonCurrentAssets: 'other_non_current_assets',
  assets: 'total_assets',
  accountsPayable: 'accounts_payable',
  accruedExpensesAndOtherCurrentLiabilities:
    'accrued_expenses_and_other_current_liabilities',
  shortTermDebt: 'short_term_debt',
  totalCurrentLiabilities: 'total_current_liabilities',
  longTermDebt: 'long_term_debt',
  otherNonCurrentLiabilities: 'other_non_current_liabilities',
  liabilities: 'total_liabilities',
  retainedEarnings: 'retained_earnings',
  accumulatedOtherComprehensiveIncomeLoss:
    'accumulated_other_comprehensive_income_loss',
  equity: 'total_equity',
  shares: 'total_shares_outstanding',
  totalAssets: 'total_assets',
  totalLiabilities: 'total_liabilities',
  totalEquity: 'total_equity',
  sharesOutstanding: 'total_shares_outstanding',
  operatingCashFlow: 'operating_cash_flow',
  investingCashFlow: 'investing_cash_flow',
  financingCashFlow: 'financing_cash_flow',
  freeCashFlow: 'free_cash_flow',
  capex: 'capital_expenditure',
  capitalExpenditure: 'capital_expenditure',
};

export function resolveStatementMetricTargetField(
  metricKey: string,
): TargetField | null {
  return STATEMENT_METRIC_TARGET_FIELDS[metricKey] ?? null;
}
