BareGit
#pragma once

#include <cstdint>
#include <filesystem>
#include <string>

#include <mw/error.hpp>

#include "card.h"

/// Metadata for one validated, normalized card image.
struct ProcessedImage
{
    /// Canonical path of the normalized image.
    std::filesystem::path path;

    /// Lowercase extension stored in the card row.
    std::string extension;

    /// Decoded image width in pixels.
    std::uint32_t width;

    /// Decoded image height in pixels.
    std::uint32_t height;

    /// Whether the decoded image contains an alpha channel.
    bool has_alpha;
};

/// Validate and normalize untrusted card image uploads.
class ImageProcessor
{
public:
    /// Construct an image processor with output settings.
    ImageProcessor(int avif_quality, std::uint32_t thumbnail_long_side);

    /// Validate and normalize an uploaded image for its logical role.
    mw::E<ProcessedImage> process(
        const std::filesystem::path& input,
        CardAssetType type) const;

    /// Generate the fixed-size index thumbnail for a plain card.
    mw::E<ProcessedImage> generatePlainThumbnail(
        const ProcessedImage& artwork,
        const std::filesystem::path& output) const;

private:
    int avif_quality_;
    std::uint32_t thumbnail_long_side_;
};