import Foundation

class FileUtils {
    private static let CAP_PLUGIN_PREFS = "CapPluginPrefs"
    
    private init() {
        // Private constructor to prevent instantiation
    }
    
    static func writeInLocalFile(fileName: String, content: String) {
        if let filePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(fileName) {
            do {
                try content.write(to: filePath, atomically: true, encoding: .utf8)
            } catch {
                logger(.error, message: "Can't write \(fileName)")
            }
        }
    }
    
    static func getLocalFile(fileName: String) -> [String: String]? {
        if let filePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(fileName) {
            do {
                let content = try String(contentsOf: filePath, encoding: .utf8)
                return ["content": content, "filePath": filePath.path]
            } catch {
                return nil
            }
        }
        return nil
    }
    
    static func writeValue(key: String, value: String) {
        UserDefaults.standard.setValue(value, forKey: key)
    }

    static func readValue(key: String) -> String? {
        return UserDefaults.standard.string(forKey: key)
    }

    
}
