# Copyright Sierra
import json
from typing import Optional

from murmur.data_model.tasks import Task
from murmur.domains.airline.data_model import FlightDB
from murmur.domains.airline.tools import AirlineTools
from murmur.domains.airline.utils import (
    AIRLINE_DB_PATH,
    AIRLINE_POLICY_PATH,
    AIRLINE_TASK_SET_PATH,
    AIRLINE_INJECTION_TASKS_PATH,
)
from murmur.environment.environment import Environment


def get_environment(
    db: Optional[FlightDB] = None,
    solo_mode: bool = False,
) -> Environment:
    if solo_mode:
        raise ValueError("Airline domain does not support solo mode")
    if db is None:
        db = FlightDB.load(AIRLINE_DB_PATH)
    tools = AirlineTools(db)
    with open(AIRLINE_POLICY_PATH, "r") as fp:
        policy = fp.read()
    return Environment(
        domain_name="airline",
        policy=policy,
        tools=tools,
    )


def get_tasks() -> list[Task]:
    with open(AIRLINE_TASK_SET_PATH, "r") as fp:
        tasks = json.load(fp)
    return [Task.model_validate(task) for task in tasks]


def get_injection_tasks() -> list[Task]:
    with open(AIRLINE_INJECTION_TASKS_PATH, "r") as fp:
        tasks = json.load(fp)
    return [Task.model_validate(task) for task in tasks]