// SPDX-License-Identifier: MIT

package setting

import "strings"

// PDF holds server-side configuration for Markdown → PDF export.
//
// NOTE: The worker-facing config surface is represented in services/pdfexport and
// is always marshaled with the exact JSON keys required by the worker contract.
var PDF = struct {
	Enabled     bool
	Determinism string
	Timestamp   string
	Typography  string

	OrphansWidowsEnforce bool `ini:"ORPHANS_WIDOWS_ENFORCE"`
	FooterEnabled        bool `ini:"FOOTER_ENABLED"`

	Mermaid struct {
		Strategy string
		Caption  bool
	}

	// ContainerRuntime is the executable used to run the worker container.
	// Typical values: docker, podman.
	ContainerRuntime string `ini:"CONTAINER_RUNTIME"`
	// WorkerImage is the container image reference to run.
	WorkerImage string `ini:"WORKER_IMAGE"`
}{
	Enabled:              false,
	Determinism:          "strict",
	Timestamp:            "commit_time",
	Typography:           "professional",
	OrphansWidowsEnforce: true,
	FooterEnabled:        true,
	ContainerRuntime:     "podman",
	WorkerImage:          "localhost/forgejo/pdf-worker:v0.1",
	Mermaid:              struct{ Strategy string; Caption bool }{Strategy: "balanced", Caption: false},
}

func loadPDFFrom(rootCfg ConfigProvider) {
	mustMapSetting(rootCfg, "pdf", &PDF)
	// Allow nested mermaid configuration under [pdf.mermaid].
	mustMapSetting(rootCfg, "pdf.mermaid", &PDF.Mermaid)

	PDF.Determinism = strings.ToLower(PDF.Determinism)
	PDF.Timestamp = strings.ToLower(PDF.Timestamp)
	PDF.Typography = strings.ToLower(PDF.Typography)
	PDF.Mermaid.Strategy = strings.ToLower(PDF.Mermaid.Strategy)
}
