import Foundation

struct FileService: FileServicing {
    
    // MARK: Functions
    
    func listItems(in folder: String) async throws (FileServiceError) -> [String] {
        let fileManager = FileManager.default
        
        guard !folder.isEmpty else {
            throw .folderPathEmpty
        }
        
        var isFolder: ObjCBool = false
        
        guard fileManager.fileExists(atPath: folder, isDirectory: &isFolder) else {
            throw .folderNotFound
        }
        
        guard isFolder.boolValue else {
            throw .folderNotDirectory
        }

        do {
            return try fileManager.contentsOfDirectory(atPath: folder)
        } catch {
            throw .other(error)
        }
    }
    
}
