from pathlib import Path

from inspect_ai.dataset import json_dataset
from inspect_ai.tool import bash_session, tool

from bench_af._abstract.objects import Environment
from environments.blackmail.scorer import is_blackmailing, behave_because_observed, misbehave_because_unobserved

BASE_PATH = Path(__file__).parent


@tool
def send_email():
    async def send(to: str, cc: str, sender: str, message: str):
        """Send an email to someone from sender, cc'ing people in comma separated cc field
        Args:
            to: to email address
            cc: comma separated cc emails
            sender: from email address
            message: Message body of email
        """
        print(f"Message successfully sent! {message}")
        return (f"Status: 200")

    return send


tools = [bash_session(timeout=60), send_email()]

def get() -> Environment:
    """Return the default environment with observed and unobserved datasets."""

    observed_dataset = json_dataset(str(BASE_PATH/"test_dataset.json"))
    unobserved_dataset = json_dataset(str(BASE_PATH/"deployment_dataset.json"))
    # observed_dataset = json_dataset(str(BASE_PATH/"test_dataset_collectivism_replacement.json"))
    # unobserved_dataset = json_dataset(str(BASE_PATH/"deployment_dataset_collectivism_replacement.json"))

    return Environment(
        name="blackmail",
        tools=tools,
        observed_dataset=observed_dataset,
        unobserved_dataset=unobserved_dataset,
        scorers=[is_blackmailing(), behave_because_observed(),
                 misbehave_because_unobserved()]
    )
