// // ServerTypes_Fixed.swift // iKeyMon // // Fixed server types matching your existing code structure // import Foundation // MARK: - Server API Response Types struct ServerAPIResponse: Codable { let data: T let status: String let timestamp: Date let version: String enum CodingKeys: String, CodingKey { case data case status case timestamp case version } } // MARK: - Server API Version struct ServerAPIVersion: Codable { let major: Int let minor: Int let patch: Int let string: String init(major: Int, minor: Int, patch: Int = 0) { self.major = major self.minor = minor self.patch = patch self.string = "\(major).\(minor).\(patch)" } init(from versionString: String) throws { let components = versionString.split(separator: ".").compactMap { Int($0) } guard components.count >= 2 else { throw DecodingError.dataCorrupted( DecodingError.Context(codingPath: [], debugDescription: "Invalid version string format") ) } self.major = components[0] self.minor = components[1] self.patch = components.count > 2 ? components[2] : 0 self.string = versionString } } // MARK: - Server API Response Factory class ServerAPIResponseFactory { static func createResponse(data: T, status: String = "success") -> ServerAPIResponse { return ServerAPIResponse( data: data, status: status, timestamp: Date(), version: "1.0" ) } static func createErrorResponse(error: String) -> ServerAPIResponse { return ServerAPIResponse( data: error, status: "error", timestamp: Date(), version: "1.0" ) } }