//
//  FontRegistration.swift
//
//
//  Created by Victor on 12/06/2024.
//

import CoreGraphics
import CoreText
import UIKit

struct FontRegistration {
    public enum FontError: Swift.Error {
        case failedToRegisterFont
    }
    
    func registerFonts() throws {
        let fontNames = [
            "TTChocolates-Bold-Italic",
            "TTChocolates-Bold",
            "TTChocolates-DemiBold",
            "TTChocolates-Medium",
            "TTChocolates-MediumIt"
        ]
        
        for name in fontNames {
            guard let asset = NSDataAsset(name: "Fonts/\(name)"),
                  let provider = CGDataProvider(data: asset.data as NSData),
                  let font = CGFont(provider),
                  CTFontManagerRegisterGraphicsFont(font, nil)
            else {
                throw FontError.failedToRegisterFont
            }
        }
    }
}
