// The MIT License (MIT)
//
// Copyright (C) 2026 Scott Duensing
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

// hlpcCompile.h -- DVX Help Compiler library interface
//
// Allows the help compiler to be called as a function (from the
// loader for startup recompilation) or as a standalone executable.
// The progress callback enables real-time progress bar updates.

#ifndef HLPC_COMPILE_H
#define HLPC_COMPILE_H

#include <stdint.h>

// Progress callback: called after each input file in pass 1 and
// after each of passes 2-5. total is set on the first call and
// stays constant. current increments from 0 to total.
typedef void (*HlpcProgressFnT)(void *ctx, int32_t current, int32_t total);

// Compile help source files into a binary .hlp file.
//
// inputFiles: array of .dhs source file paths
// inputCount: number of input files
// outputPath: path to write the .hlp file
// imageDir:   directory to search for .image references (NULL = ".")
// htmlPath:   if non-NULL, also emit HTML to this path
// quiet:      suppress informational output
// progressFn: progress callback (NULL = no progress reporting)
// progressCtx: opaque context passed to progressFn
//
// Values for the quiet parameter.
#define HLPC_VERBOSE 0
#define HLPC_QUIET   1

// Returns 0 on success, non-zero on error.
int32_t hlpcCompile(const char **inputFiles, int32_t inputCount, const char *outputPath, const char *imageDir, const char *htmlPath, int32_t quiet, HlpcProgressFnT progressFn, void *progressCtx);

// Return the number of progress steps for a given input count.
// This is inputCount (one per file in pass 1) + 4 (passes 2-5).
// Useful for pre-computing the total across multiple compilations.
static inline int32_t hlpcProgressTotal(int32_t inputCount) {
    return inputCount + 4;
}

#endif // HLPC_COMPILE_H
