import Foundation public struct SetupCatalog: Sendable, Equatable, Codable { public var setups: [SavedSetup] public init(setups: [SavedSetup] = []) throws { self.setups = setups try validate() } public func validate() throws { var ids: Set = [] var names: Set = [] for setup in setups { try setup.validate() guard ids.insert(setup.id).inserted else { throw SavedSetupError.duplicateID(setup.id) } guard names.insert(setup.normalizedName).inserted else { throw SavedSetupError.duplicateName(setup.name) } } } private enum CodingKeys: String, CodingKey { case setups } public init(from decoder: any Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) try self.init(setups: values.decode([SavedSetup].self, forKey: .setups)) } }