//
//  Font.Weight.swift
//  TheNoiseClock
//
//  Created by Matt Bruce on 9/11/25.
//
import SwiftUI

extension Font.Weight: @retroactive RawRepresentable, @retroactive CaseIterable {
    public init?(rawValue: String) {
        switch rawValue.lowercased() {
        case "ultra light", "ultralight":
            self = .ultraLight
        case "thin":
            self = .thin
        case "light":
            self = .light
        case "regular":
            self = .regular
        case "medium":
            self = .medium
        case "semibold", "semi bold":
            self = .semibold
        case "bold":
            self = .bold
        case "heavy":
            self = .heavy
        case "black":
            self = .black
        default:
            return nil
        }
    }
    
    public var rawValue: String {
        switch self {
        case .ultraLight: return "Ultra Light"
        case .thin: return "Thin"
        case .light: return "Light"
        case .regular: return "Regular"
        case .medium: return "Medium"
        case .semibold: return "Semibold"
        case .bold: return "Bold"
        case .heavy: return "Heavy"
        case .black: return "Black"
        default: return "Regular"
        }
    }

    public static var allCases: [Font.Weight] {
        [.ultraLight, .thin, .light, .regular, .medium, .semibold, .bold, .heavy, .black]
    }
    
    var uiFontWeight: UIFont.Weight {
        switch self {
        case .ultraLight: return .ultraLight
        case .thin: return .thin
        case .light: return .light
        case .regular: return .regular
        case .medium: return .medium
        case .semibold: return .semibold
        case .bold: return .bold
        case .heavy: return .heavy
        case .black: return .black
        default: return .regular
        }
    }
    
    var uiFontWeightSuffix: String {
        switch self {
        case .ultraLight: return "-UltraLight"
        case .thin: return "-Thin"
        case .light: return "-Light"
        case .regular: return ""
        case .medium: return "-Medium"
        case .semibold: return "-SemiBold"
        case .bold: return "-Bold"
        case .heavy: return "-Heavy"
        case .black: return "-Black"
        default: return ""
        }
    }
}
