#pragma once
#include "gallery/gallery_report.hpp"
#include "types.hpp"
#include <string>

// Build an ActorGallery from a directory tree:
//
//   gallery_root/
//     nm0000093_Brad_Pitt/
//       img1.jpg
//       img2.jpg
//       ...
//     nm0000129_Cate_Blanchett/
//       ...
//
// Each subdirectory name is parsed as "<imdb_id>_<Name_With_Underscores>".
// For every image:
//   1. Detect face with SCRFD-500MF (expect exactly one; warn and skip if 0 or >1).
//   2. Align with ArcFace 5-point transform → 112×112 crop.
//   3. Embed with ArcFace ONNX → 512-dim L2-normalised embedding.
// All embeddings are stored (best-of-N match at query time).
//
// Returns a gallery ready to pass to save_gallery() / IdentityMatcherFunc.

struct BuildConfig {
    std::string gallery_root;   // directory tree described above
    std::string detector_model;
    std::string arcface_model;
    float       detector_conf{0.5f};
    float       detector_nms{0.4f};
    int         max_side{500};  // downscale source images to this max dimension

    /// Minimum detected-face side, in pixels of the (possibly downscaled)
    /// source image. 0 disables the check.
    ///
    /// References below this are dropped rather than upscaled: a face smaller
    /// than the embedder's input is off-distribution, and a bad reference
    /// poisons every match against that identity for the life of the gallery.
    /// Mirrors the inference-side --min-face-px so the gallery is built from
    /// the same face scales it will be matched against.
    float       min_face_px{0.f};
                                // before detection — TMDB portraits are ~2k px,
                                // SCRFD trains on smaller faces and detection
                                // confidence drops on huge inputs. 0 = disabled.
};

ActorGallery build_gallery(const BuildConfig& cfg);
