"""Generate the golden ``LogRecord`` conformance artifacts (Wave 1.5).

Writes the two files the Zig/TS emitters pin against, from the single
source of truth in :mod:`mgf.common.observability._conformance`:

  - ``src/mgf/common/observability/schema/log_record_fixture.jsonl``
  - ``src/mgf/common/observability/schema/log_record_schema.json``

Usage (one-off regeneration)::

    uv run python tools/gen_log_record_schema.py

Pinned by ``tests/unit/observability/test_log_record_conformance.py`` —
running the generator MUST reproduce the files on disk byte-for-byte; CI
fails if they drift (OB-10).
"""

from __future__ import annotations

from pathlib import Path

from mgf.common.observability._conformance import (
    FIXTURE_RESOURCE,
    SCHEMA_RESOURCE,
    render_fixture,
    render_schema_json,
)


def main() -> int:
    repo_root = Path(__file__).resolve().parent.parent
    schema_dir = repo_root / "src" / "mgf" / "common" / "observability" / "schema"
    fixture = schema_dir / FIXTURE_RESOURCE
    schema = schema_dir / SCHEMA_RESOURCE
    fixture_body = render_fixture()
    fixture.write_text(fixture_body, encoding="utf-8")
    schema.write_text(render_schema_json(), encoding="utf-8")
    print(f"wrote {fixture}")
    print(f"wrote {schema}")

    # The Zig reference client can't read the packaged Python resource, so it
    # @embedFiles a vendored copy of the same golden. Keep it in sync here;
    # the conformance test pins it (so the copy can never silently drift).
    zig_testdata = repo_root / "clients" / "zig" / "testdata" / FIXTURE_RESOURCE
    if zig_testdata.parent.is_dir():
        zig_testdata.write_text(fixture_body, encoding="utf-8")
        print(f"wrote {zig_testdata}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
