import slugify from 'slugify';
import { v4 as uuid } from 'uuid';

export function sanitizeFileName(fileName: string) {
  const cleaned = fileName.replace(/[^a-zA-Z0-9._-]/g, '-');
  return cleaned.toLowerCase().endsWith('.zip') ? cleaned : `${cleaned}.zip`;
}

export function buildMapS3Key(country: string, state: string, fileName: string) {
  const countrySlug = slugify(country, { lower: true, strict: true });
  const stateSlug = slugify(state, { lower: true, strict: true });
  return `offline-maps/${countrySlug}/${stateSlug}/${uuid()}-${sanitizeFileName(fileName)}`;
}
