//
//  CsvDocument.swift
//  FastCoster
//
//  Created by Michael Pivato on 3/2/2023.
//

import Foundation
import SwiftUI
import UniformTypeIdentifiers

struct CsvDocument: FileDocument {
    var output: String
    
    static var readableContentTypes: [UTType] {[.commaSeparatedText]}
    
    init(configuration: ReadConfiguration) throws {
        guard let data = configuration.file.regularFileContents, let string = String(data: data, encoding: .utf8) else {
            throw CocoaError(.fileReadCorruptFile)
        }
        output = string
    }
    
    init(data: String) {
        output = data
    }
    
    func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
        return FileWrapper(regularFileWithContents: output.data(using: .utf8)!)
    }
    
    
}
