"""
Starting skeleton.  Fill in the middle.

Run it locally against the sample round:

    NULLSIGHT_TRAIN=sample/train.csv \
    NULLSIGHT_TEST=sample/test.csv \
    NULLSIGHT_OUT=predictions.csv \
    python solution_template.py
    python score_local.py predictions.csv sample/test_labels.csv

Then upload the same file to the arena unchanged -- it reads its paths from
the environment, and the sandbox sets them to /data/train.csv, /data/test.csv
and /out/predictions.csv.

Available: numpy, pandas, scipy, scikit-learn, joblib.  No network.
"""

from __future__ import annotations

import os

import pandas as pd

TRAIN = os.environ.get("NULLSIGHT_TRAIN", "/data/train.csv")
TEST = os.environ.get("NULLSIGHT_TEST", "/data/test.csv")
OUT = os.environ.get("NULLSIGHT_OUT", "/out/predictions.csv")

TELEMETRY = ["ttl", "n_resolved_ips", "n_distinct_asns", "nxdomain_ratio",
             "query_count_24h", "first_seen_days_ago", "n_unique_clients"]


def main():
    train = pd.read_csv(TRAIN)      # has 'label'
    test = pd.read_csv(TEST)        # does not

    # ------------------------------------------------------------------
    # Your work goes here.  Three things worth thinking about before you
    # start typing:
    #
    #   * Which part of `domain` is actually attacker-controlled?  A lot of
    #     perfectly benign traffic has a high-entropy leftmost label.
    #
    #   * Some malicious families are ordinary English words glued together.
    #     No amount of character-level modelling will separate those from a
    #     real brandable domain.  Something else in the row will.
    #
    #   * The test split contains families that are in no training split, and
    #     the class balance is not what you saw last round.  A threshold of
    #     0.5 is a choice, and usually the wrong one.
    # ------------------------------------------------------------------
    pred = pd.Series(0, index=test.index)

    os.makedirs(os.path.dirname(OUT) or ".", exist_ok=True)
    pd.DataFrame({"id": test["id"], "label": pred.astype(int)}).to_csv(
        OUT, index=False)


if __name__ == "__main__":
    main()
