import pytest
import mock
import os

from arthurai.core.models import ArthurModel
from arthurai.client.base import BaseApiClient
from tests.base_test import BaseTest


@pytest.fixture(scope="session")
def mock_cred_env_vars():
    with mock.patch.dict(os.environ, {"ARTHUR_API_KEY": "access_key", "ARTHUR_ENDPOINT_URL": BaseTest._base_url}):
        yield


@pytest.fixture(scope="session")
def binary_classification_model() -> ArthurModel:
    binary_classification_model = {
        "id": "4a57c553-e787-4307-88f1-3747ec9130f5",
        "partner_model_id": "binary_classification_model",
        "input_type": "TABULAR",
        "output_type": "MULTICLASS",
        "archived": False,
        "created_at": "2020-10-26T21:43:24.632335Z",
        "updated_at": "2020-10-26T21:43:26.364596Z",
        "attributes": [
            {
                "id": "1d4bec8d-84a6-4ae7-a7ea-1a2230bb977c",
                "name": "input",
                "value_type": "INTEGER",
                "stage": "PIPELINE_INPUT",
                "position": 1,
                "categorical": False,
                "monitor_for_bias": False,
                "is_positive_predicted_attribute": False
            },
            {
                "id": "254c8f5f-f4b8-4943-89bf-db106d5ca835",
                "name": "pos_predicted_probability",
                "value_type": "FLOAT",
                "stage": "PREDICTED_VALUE",
                "position": 1,
                "categorical": False,
                "min_range": 0,
                "max_range": 1,
                "monitor_for_bias": False,
                "is_unique": False,
                "is_positive_predicted_attribute": True,
                "attribute_link": "pos_gt"
            },
            {
                "id": "ac97a47f-f755-451e-956c-d1ed52403915",
                "name": "pos_gt",
                "value_type": "INTEGER",
                "stage": "GROUND_TRUTH",
                "position": 1,
                "categorical": False,
                "min_range": 0,
                "max_range": 1,
                "monitor_for_bias": False,
                "is_unique": True,
                "is_positive_predicted_attribute": False,
                "attribute_link": "pos_predicted_probability"
            },
            {
                "id": "c2e626df-ee4c-403f-818b-f4f2d9180eab",
                "name": "neg_gt",
                "value_type": "INTEGER",
                "stage": "GROUND_TRUTH",
                "position": 2,
                "categorical": False,
                "min_range": 0,
                "max_range": 1,
                "monitor_for_bias": False,
                "is_unique": True,
                "is_positive_predicted_attribute": False,
                "attribute_link": "neg_predicted_probability"
            },
            {
                "id": "d4f04345-c92c-4959-9d92-7fe35924efeb",
                "name": "neg_predicted_probability",
                "value_type": "FLOAT",
                "stage": "PREDICTED_VALUE",
                "position": 2,
                "categorical": False,
                "min_range": 0,
                "max_range": 1,
                "monitor_for_bias": False,
                "is_unique": False,
                "is_positive_predicted_attribute": False,
                "attribute_link": "neg_gt"
            }
        ],
        "tags": [],
        "classifier_threshold": 0.5,
        "explainability": {
            "enabled": False
        },
        "is_batch": False,
        "text_delimiter": ","
    }
    yield ArthurModel(client=BaseApiClient(url="test.ai", offline=True), **binary_classification_model)
