const PRODUCT_STATUS_TRANSITIONS: Record<string, string[]> = {
  DRAFTED: ['PENDING_REVIEW'],
  PENDING_REVIEW: ['APPROVED', 'FAILED_MANUAL'],
  APPROVED: ['EXECUTING'],
  EXECUTING: ['PUBLISHED', 'FAILED_RETRYABLE', 'FAILED_MANUAL'],
  PUBLISHED: ['RECONCILED'],
  RECONCILED: [],
  FAILED_RETRYABLE: ['EXECUTING', 'FAILED_MANUAL'],
  FAILED_MANUAL: ['PENDING_REVIEW'],
};

const SYNC_STATUS_TRANSITIONS: Record<string, string[]> = {
  pending: ['published', 'failed'],
  failed: ['pending'],
  published: ['published'],
};

export function isValidProductStatusTransition(fromStatus: string, toStatus: string) {
  const normalizedFrom = fromStatus.toUpperCase();
  const normalizedTo = toStatus.toUpperCase();
  const allowed = PRODUCT_STATUS_TRANSITIONS[normalizedFrom];
  if (!allowed) {
    return false;
  }
  return allowed.includes(normalizedTo);
}

export function isValidSyncStatusTransition(fromStatus: string, toStatus: string) {
  const normalizedFrom = fromStatus.toLowerCase();
  const normalizedTo = toStatus.toLowerCase();
  const allowed = SYNC_STATUS_TRANSITIONS[normalizedFrom];
  if (!allowed) {
    return false;
  }
  return allowed.includes(normalizedTo);
}
