//
//  LNMediaFileUtils.swift
//  Lanu
//
//  Created by OneeChan on 2026/03/08.
//

import Foundation

struct LNMediaFileUtils {
    static func persistTemporaryVideo(from url: URL) -> URL? {
        let fileManager = FileManager.default
        let destinationUrl = fileManager.temporaryDirectory
            .appendingPathComponent(UUID().uuidString)
            .appendingPathExtension(url.pathExtension.isEmpty ? "mp4" : url.pathExtension)
        do {
            if fileManager.fileExists(atPath: destinationUrl.path) {
                try fileManager.removeItem(at: destinationUrl)
            }
            try fileManager.copyItem(at: url, to: destinationUrl)
            return destinationUrl
        } catch {
            return url
        }
    }
}
