import yaml
from pathlib import Path
from typing import List, Dict, Set

class ManifestParser:
    """Parses and validates the Consent Manifest (YAML)."""
    
    def __init__(self, manifest_path: str):
        self.path = Path(manifest_path)
        self.authorized_assets: Set[str] = set()

    def load(self) -> Dict:
        if not self.path.exists():
            raise FileNotFoundError(f"Manifest not found: {self.path}")
            
        with open(self.path, 'r') as f:
            data = yaml.safe_load(f)
            
        if not data or 'assets' not in data:
            raise ValueError("Invalid manifest format. Missing 'assets' key.")
            
        # Store as set of absolute paths for easy comparison
        for asset in data['assets']:
            # Assets in manifest should be relative to the manifest file or absolute
            asset_path = Path(asset)
            if not asset_path.is_absolute():
                asset_path = (self.path.parent / asset_path).resolve()
            self.authorized_assets.add(str(asset_path))
            
        return data

    def get_authorized_paths(self) -> Set[str]:
        return self.authorized_assets
