import Foundation

enum NormalPreviewKind: String, CaseIterable, Identifiable {
    case source
    case height
    case normal
    case roughness
    case gloss
    case metallic
    case occlusion
    case orm

    var id: String { rawValue }

    var title: String {
        switch self {
        case .source:
            "Source"
        case .height:
            "Height"
        case .normal:
            "Normal"
        case .roughness:
            "Roughness"
        case .gloss:
            "Gloss"
        case .metallic:
            "Metallic"
        case .occlusion:
            "AO"
        case .orm:
            "ORM"
        }
    }

    var subtitle: String {
        switch self {
        case .source:
            "Original texture"
        case .height:
            "Generated grayscale"
        case .normal:
            "RGB tangent normal"
        case .roughness:
            "PBR roughness"
        case .gloss:
            "Inverse roughness"
        case .metallic:
            "Heuristic metal mask"
        case .occlusion:
            "Generated shadow helper"
        case .orm:
            "R AO / G Rough / B Metal"
        }
    }
}

struct NormalGeneratorSettings: Equatable {
    var materialName = "BREDA_Normal"
    var outputResolution: OutputResolution = .px2048
    var strength: Double = 3.0
    var smoothing: Int = 1
    var invertHeight = false
    var flipGreen = false
    var roughnessMin: Double = 0.18
    var roughnessMax: Double = 0.82
    var metallicStrength: Double = 0.45
    var aoStrength: Double = 0.55
    var exportHeight = true
    var exportRoughness = true
    var exportGloss = true
    var exportMetallic = true
    var exportAO = true
    var exportORM = true
    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_Normal" : joined
    }
}
