"""Fixtures for Tessie."""

from copy import deepcopy
from unittest.mock import AsyncMock, patch

import pytest

from .common import (
    COMMAND_OK,
    ENERGY_HISTORY,
    LIVE_STATUS,
    PRODUCTS,
    SCOPES,
    SITE_INFO,
    TEST_STATE_OF_ALL_VEHICLES,
    TEST_VEHICLE_STATE_ONLINE,
)

# Tessie


@pytest.fixture(autouse=True)
def mock_get_state():
    """Mock get_state function."""
    with patch(
        "tesla_fleet_api.tessie.Vehicle.state",
        new_callable=AsyncMock,
    ) as mock_get_state:
        mock_get_state.return_value = TEST_VEHICLE_STATE_ONLINE
        yield mock_get_state


@pytest.fixture(autouse=True)
def mock_get_state_of_all_vehicles():
    """Mock get_state_of_all_vehicles function."""
    with patch(
        "tesla_fleet_api.tessie.Tessie.list_vehicles",
        new_callable=AsyncMock,
    ) as mock_get_state_of_all_vehicles:
        mock_get_state_of_all_vehicles.return_value = TEST_STATE_OF_ALL_VEHICLES
        yield mock_get_state_of_all_vehicles


# Fleet API
@pytest.fixture(autouse=True)
def mock_scopes():
    """Mock scopes function."""
    with patch(
        "homeassistant.components.tessie.Tessie.scopes",
        return_value=SCOPES,
    ) as mock_scopes:
        yield mock_scopes


@pytest.fixture(autouse=True)
def mock_products():
    """Mock Tesla Fleet Api products method."""
    with patch(
        "homeassistant.components.tessie.Tessie.products", return_value=PRODUCTS
    ) as mock_products:
        yield mock_products


@pytest.fixture(autouse=True)
def mock_request():
    """Mock Tesla Fleet API request method."""
    with patch(
        "homeassistant.components.tessie.Tessie._request",
        return_value=COMMAND_OK,
    ) as mock_request:
        yield mock_request


@pytest.fixture(autouse=True)
def mock_live_status():
    """Mock Tesla Fleet API EnergySpecific live_status method."""
    with patch(
        "tesla_fleet_api.tessie.EnergySite.live_status",
        side_effect=lambda: deepcopy(LIVE_STATUS),
    ) as mock_live_status:
        yield mock_live_status


@pytest.fixture(autouse=True)
def mock_site_info():
    """Mock Tesla Fleet API EnergySpecific site_info method."""
    with patch(
        "tesla_fleet_api.tessie.EnergySite.site_info",
        side_effect=lambda: deepcopy(SITE_INFO),
    ) as mock_live_status:
        yield mock_live_status


@pytest.fixture(autouse=True)
def mock_energy_history():
    """Mock Tesla Fleet API EnergySite energy_history method."""
    with patch(
        "tesla_fleet_api.tessie.EnergySite.energy_history",
        side_effect=lambda *a, **kw: deepcopy(ENERGY_HISTORY),
    ) as mock_energy_history:
        yield mock_energy_history
