import Foundation

enum OutputResolution: String, CaseIterable, Identifiable {
    case matchBase
    case px512
    case px1024
    case px2048
    case px4096

    var id: String { rawValue }

    var title: String {
        switch self {
        case .matchBase:
            "Base Size"
        case .px512:
            "512"
        case .px1024:
            "1024"
        case .px2048:
            "2048"
        case .px4096:
            "4096"
        }
    }

    var fixedPixels: Int? {
        switch self {
        case .matchBase:
            nil
        case .px512:
            512
        case .px1024:
            1024
        case .px2048:
            2048
        case .px4096:
            4096
        }
    }
}

struct ConversionSettings: Equatable {
    var materialName = "BREDA_PBR_Material"
    var outputResolution: OutputResolution = .px2048
    var flipNormalGreen = false
    var roughnessInputIsGloss = false
    var defaultOcclusion: Double = 1.0
    var defaultRoughness: Double = 0.65
    var defaultMetallic: Double = 0.0
    var exportGLTF = true
    var exportNotes = true

    var safeMaterialName: String {
        let allowed = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-_ "))
        let filtered = materialName.unicodeScalars.map { allowed.contains($0) ? Character($0) : "_" }
        let joined = String(filtered)
            .trimmingCharacters(in: .whitespacesAndNewlines)
            .replacingOccurrences(of: " ", with: "_")
        return joined.isEmpty ? "BREDA_PBR_Material" : joined
    }
}

struct ExportResult {
    let folderURL: URL
    let files: [String]
}
