"""Security-lake playbook, step 6: declare the detection-quality protocol.

The protocol fixes, before any dataset is built, what the report of step 11
judges: the label, the metrics, the internal quality safeguard the model must
beat, the margins, and the review bands with their alert budget. Its class is
`fixture`: this lake comes from a seeded generator, and the report can never claim more.
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))  # playbooks/playbook_api.py
from playbook_api import Api, State

api, state = Api(), State("security-lake")

label_id = state["label_ids"]["repeated_logon_failure_1d"]
protocol = api.post(
    "/protocols",
    {
        "name": "security lake detection quality (fixture)",
        "provenance": "fixture",
        "labels": [label_id],
        "metrics": ["alert_precision@budget", "auc", "precision@list"],
        "arms": ["gbm_tuned"],
        "margins": {"alert_precision@budget": 0.0, "auc": 0.0, "precision@list": 0.0},
        "banding_policy": {
            "bands": [
                {"band": "review", "min_score": 0.5},
                {"band": "watch", "min_score": 0.2},
                {"band": "baseline", "min_score": 0.0},
            ],
            "list_size": 40,
            "alert_budget": 20,
        },
    },
    key="security-lake-protocol",
)
print(f"provenance: {protocol['provenance']}")
print(f"declared_at: {protocol['declared_at']}")
state.update(
    protocol_id=protocol["protocol_id"],
    banding_policy=protocol["banding_policy"],
    banding_policy_fingerprint=protocol["banding_policy_fingerprint"],
)
