import type { GpoArtifactRole, GpoPolicyScope } from '../domain/gpo-ingestion'; export interface GpoArtifactClassification { role: GpoArtifactRole; scope: GpoPolicyScope; } const metadataNames = new Set(['backup.xml', 'bkupinfo.xml', 'gpreport.xml']); function policyScope(segments: string[]): GpoPolicyScope { const hasComputer = segments.includes('machine'); const hasUser = segments.includes('user'); if (hasComputer === hasUser) return hasComputer ? 'shared' : 'unknown'; return hasComputer ? 'computer' : 'user'; } export function classifyGpoArtifactPath(relativePath: string): GpoArtifactClassification { const segments = relativePath.split('/').map(segment => segment.toLocaleLowerCase('en-US')); const name = segments.at(-1) ?? ''; const scope = policyScope(segments); if (metadataNames.has(name) && !segments.includes('domainsysvol')) return { role: 'backup-metadata', scope: 'shared' }; if (segments.includes('scripts')) return { role: 'script', scope }; if (name === 'registry.pol') return { role: 'registry-policy', scope }; if (name === 'gpttmpl.inf') return { role: 'security-template', scope }; if (name === 'audit.csv' && segments.includes('audit')) return { role: 'advanced-audit-policy', scope }; if (name.endsWith('.xml') && segments.includes('preferences')) return { role: 'group-policy-preference', scope }; return { role: 'unknown', scope }; } export function isGpoSysvolPath(relativePath: string): boolean { const path = `/${relativePath.toLocaleLowerCase('en-US')}/`; return path.includes('/domainsysvol/gpo/'); }