import { Signature } from "@/lib/types";

export const parseSignature = (text: string): Omit<Signature, 'system' | 'sysid'> | null => {
  const parts = text.split('\t');
  if (parts.length < 4) return null;

  // Validate signature identifier format (3 letters, dash, 3 numbers)
  const signatureIdentifierRegex = /^\w{3}-\d{3}$/;
  if (!signatureIdentifierRegex.test(parts[0])) {
    return null;
  }

  return {
    identifier: parts[0],
    type: parts[2],
    signame: parts[3],
    scanned: parts.length > 4 ? parts[4] : undefined,
    dangerous: false // TODO: Implement dangerous signature detection
  };
};

export const parseScannedPercentage = (scannedString?: string): number => {
  if (!scannedString) return 0;
  const match = scannedString.match(/(\d+(?:\.\d+)?)%/);
  return match ? parseFloat(match[1]) : 0;
};
