// lib/accounting/core/validation-rules.ts

import { JournalLine } from './journal-types';

/**
 * List of core validation rules for journal lines.
 * These rules must be enforced before posting any accounting event.
 */
export const CORE_VALIDATION_RULES = [
  'No negative debit or credit values',
  'Debit and credit must not both be zero',
  'Account code must be valid and active',
  'Branch ID required for all lines',
  'Project ID required for project accounts',
  'Cost center and project cannot both be set for same line',
  'Currency and precision must match snapshot',
  'No orphaned supplier/customer IDs',
  'No duplicate account/dimension combinations',
  'All required dimensions present',
  'No posting to closed periods',
  'No reversal without original journal',
  'No FX revaluation on non-FX accounts',
  'No posting if document is immutable',
  'No posting if open balance is locked',
  'All validations must pass before posting',
];

export function validateJournalLine(line: JournalLine): string[] {
  const errors: string[] = [];
  if (line.debit < 0 || line.credit < 0) errors.push('Negative debit/credit');
  if (line.debit === 0 && line.credit === 0) errors.push('Zero debit/credit');
  // ...implement other rules as needed
  return errors;
}
