/*
 * Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
 * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <LibGfx/Font/UnicodeRange.h>
#include <LibWeb/CSS/FontComputer.h>
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/CSS/URL.h>

namespace Web::CSS {

class ParsedFontFace {
public:
    struct Source {
        Variant<FlyString, URL> local_or_url;
        Optional<FlyString> format;
        Vector<FontTech> tech;
    };

    static Vector<Source> sources_from_style_value(StyleValue const&);
    static ParsedFontFace from_descriptors(CSSFontFaceDescriptors const&);

    ParsedFontFace(GC::Ref<CSSRule> parent_rule, FlyString font_family, Optional<FontWeightRange> weight, Optional<int> slope, Optional<int> width, Vector<Source> sources, Vector<Gfx::UnicodeRange> unicode_ranges, Optional<Percentage> ascent_override, Optional<Percentage> descent_override, Optional<Percentage> line_gap_override, FontDisplay font_display, Optional<FlyString> font_named_instance, Optional<FlyString> font_language_override, Optional<OrderedHashMap<FlyString, i32>> font_feature_settings, Optional<OrderedHashMap<FlyString, double>> font_variation_settings);
    ~ParsedFontFace() = default;

    GC::Ref<CSSRule> parent_rule() const { return m_parent_rule; }
    Optional<Percentage> ascent_override() const { return m_ascent_override; }
    Optional<Percentage> descent_override() const { return m_descent_override; }
    FontDisplay font_display() const { return m_font_display; }
    FlyString const& font_family() const { return m_font_family; }
    Optional<OrderedHashMap<FlyString, i32>> font_feature_settings() const { return m_font_feature_settings; }
    Optional<FlyString> font_language_override() const { return m_font_language_override; }
    Optional<FlyString> font_named_instance() const { return m_font_named_instance; }
    Optional<OrderedHashMap<FlyString, double>> font_variation_settings() const { return m_font_variation_settings; }
    Optional<int> slope() const { return m_slope; }
    Optional<FontWeightRange> weight() const { return m_weight; }
    Optional<int> width() const { return m_width; }
    Optional<Percentage> line_gap_override() const { return m_line_gap_override; }
    Vector<Source> const& sources() const { return m_sources; }
    Vector<Gfx::UnicodeRange> const& unicode_ranges() const { return m_unicode_ranges; }

private:
    GC::Ref<CSSRule> m_parent_rule;
    FlyString m_font_family;
    Optional<FlyString> m_font_named_instance;
    Optional<FontWeightRange> m_weight;
    Optional<int> m_slope;
    Optional<int> m_width;
    Vector<Source> m_sources;
    Vector<Gfx::UnicodeRange> m_unicode_ranges;
    Optional<Percentage> m_ascent_override;
    Optional<Percentage> m_descent_override;
    Optional<Percentage> m_line_gap_override;
    FontDisplay m_font_display;
    Optional<FlyString> m_font_language_override;
    Optional<OrderedHashMap<FlyString, i32>> m_font_feature_settings;
    Optional<OrderedHashMap<FlyString, double>> m_font_variation_settings;
};

}
