# ruff: noqa: T201  -- a runnable example: it reports its progress with print().
"""Clinical Trials 1.0.0: first dataset with the Python SDK.

GENERATED by tools/pack_assets.py.

Needs ``pip install datanivra-sdk``, DATANIVRA_API_URL and DATANIVRA_API_TOKEN. The SDK talks to
the control plane only (metadata); your data is processed by the agent in your network.
Replace the placeholder ids in ``api/*.json`` before running.
"""

from __future__ import annotations

import json
import os
from pathlib import Path

from datanivra_sdk import DataNivraClient

HERE = Path(__file__).resolve().parent
PACK_ID = "clinical-trials"


def body(name: str) -> dict[str, object]:
    return dict(json.loads((HERE / "api" / name).read_text(encoding="utf-8")))


def main() -> None:
    with DataNivraClient(os.environ["DATANIVRA_API_URL"]) as api:
        api.set_token(os.environ["DATANIVRA_API_TOKEN"])  # your session token; never commit it
        detail = api.get_industry_pack(PACK_ID)
        print("activation:", detail.activation, "executable:", detail.executable)
        api.enable_industry_pack(PACK_ID)
        drafts = api.create_pack_policy_drafts(PACK_ID, body("policy-drafts.json"))
        for draft in drafts.drafts:
            api.submit_policy_version(draft.policy_id, draft.version)  # a second person approves
        request = api.create_dataset_request(body("dataset-request.json"))
        print("dataset request:", request.id, request.status)
        for report in api.list_certification_reports().items:
            print("certification:", report.dataset_id, report.status)


if __name__ == "__main__":
    main()
