// lib/accounting/core/dimension-validator.ts

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

export interface DimensionValidationResult {
  valid: boolean;
  missing?: string[];
  conflicts?: string[];
  errors?: string[];
}

export function validateDimensions(line: JournalLine, _context: PostingContext): DimensionValidationResult {
  // Example logic (to be expanded per business rules):
  const missing: string[] = [];
  const conflicts: string[] = [];

  // Example: projectId required for certain accounts
  if (line.accountCode.startsWith('53') && !line.projectId) {
    missing.push('projectId');
  }
  // Example: branchId required for all lines
  if (!line.branchId) {
    missing.push('branchId');
  }
  // Example: costCenterId and projectId should not both be set for this account
  if (line.accountCode.startsWith('53') && line.costCenterId && line.projectId) {
    conflicts.push('costCenterId+projectId');
  }
  return {
    valid: missing.length === 0 && conflicts.length === 0,
    missing,
    conflicts,
    errors: [...missing, ...conflicts],
  };
}
