# Path: app/model/chain.py
# class Chain:
#     def __init__(self, users: List[User]):
#         self._users = users
#     
#     def to_json(self):
#         return [user.to_json() for user in self._users]
# 
# Path: app/model/response.py
# class Response(dict):
#     def __init__(self, status, data):
#         super().__init__()
#         
#         self["status"] = status
#         self["data"] = data
# 
# class Status:
#     OK = "OK"
#     ERROR = "ERROR"
# 
# Path: app/model/users_graph.py
# class UsersGraph:
#     def __init__(self, users: List[User], mutual_ids: Dict[int, List[int]]):
#         self._users = users
#         
#         self._connections = []
#         for user_id, mutual_friends_ids in mutual_ids.items():
#             for mutual_friend_id in mutual_friends_ids:
#                 self.add_connection(user_id, mutual_friend_id)
# 
#     def add_connection(self, user_id1, user_id2):
#         connection = {user_id1, user_id2}
#         if connection not in self._connections:
#             self._connections.append(connection)
#     
#     @property
#     def users(self):
#         return self._users
# 
#     @property
#     def connections(self) -> List[Set[int]]:
#         return self._connections
#     
#     def to_json(self):
#         return dict(friends=[user.to_json() for user in self._users],
#                     connections=[
#                         dict(source=min(connection), target=max(connection))
#                         for connection in self._connections])
# 
# Path: app/services/friends_chain.py
# class _Node:
# class _Tree(dict):
#     def __init__(self, user_id: int, parents: List[int] = None):
#     def id(self) -> int:
#     def parents(self) -> List[int]:
#     def add(self, node: _Node):
#     def get_by_id(self, user_id: int) -> _Node:
#     def is_id_exists(self, user_id: int):
#     def nodes(self) -> List[_Node]:
# def _build_tree(root_id: int, max_depth: SupportsInt) -> _Tree:
#     def add_next_level(prev_level: List[int], depth: int, parents: List[int]):
# def _find_common_friend(root_id: int, tree: _Tree,
#                         max_depth: SupportsInt) -> Optional[List[int]]:
#     def check_next_level(prev_level: List[int], depth: int,
#                          parents: List[int]) -> Optional[List[int]]:
# def find_chain(user1: int, user2: int,
#                max_length: int = 5) -> Optional[List[int]]:
# 
# Path: app/services/mutual_friends.py
# def get_mutual_friends(user_id: int):
# 
# Path: app/services/temperature_map.py
# def calculate_color(value, interval_length):
# 
# Path: app/services/vk.py
# def get_user(user_id) -> User:
# def get_users(user_ids: Iterable[int]) -> List[User]:
# def get_friends_count(user_id: int) -> int:
# def get_friends(user_id: int) -> List[User]:
# def get_friends_ids(user_id: int) -> List[int]:
# def get_friends_ids_batch(user_ids: List[int]) -> List[List[int]]:
# def get_mutual_friends_ids(user1: int, user2: int) -> List[int]:
# def get_mutual_friends_ids_batch(user_ids: List[int],
#                                  my_id: int) -> Dict[int, List[int]]:


from flask import Blueprint, jsonify, request
from app.model import Chain, Response, Status, UsersGraph
from app.services import friends_chain, mutual_friends, temperature_map, vk


api = Blueprint('api', __name__)


@api.route("/api/user")
def get_user():
    user_id = request.args.get("userId")
    
    try:
        user = vk.get_user(user_id)

# Path: app/model/chain.py
# class Chain:
#     def __init__(self, users: List[User]):
#         self._users = users
#     
#     def to_json(self):
#         return [user.to_json() for user in self._users]
# 
# Path: app/model/response.py
# class Response(dict):
#     def __init__(self, status, data):
#         super().__init__()
#         
#         self["status"] = status
#         self["data"] = data
# 
# class Status:
#     OK = "OK"
#     ERROR = "ERROR"
# 
# Path: app/model/users_graph.py
# class UsersGraph:
#     def __init__(self, users: List[User], mutual_ids: Dict[int, List[int]]):
#         self._users = users
#         
#         self._connections = []
#         for user_id, mutual_friends_ids in mutual_ids.items():
#             for mutual_friend_id in mutual_friends_ids:
#                 self.add_connection(user_id, mutual_friend_id)
# 
#     def add_connection(self, user_id1, user_id2):
#         connection = {user_id1, user_id2}
#         if connection not in self._connections:
#             self._connections.append(connection)
#     
#     @property
#     def users(self):
#         return self._users
# 
#     @property
#     def connections(self) -> List[Set[int]]:
#         return self._connections
#     
#     def to_json(self):
#         return dict(friends=[user.to_json() for user in self._users],
#                     connections=[
#                         dict(source=min(connection), target=max(connection))
#                         for connection in self._connections])
# 
# Path: app/services/friends_chain.py
# class _Node:
# class _Tree(dict):
#     def __init__(self, user_id: int, parents: List[int] = None):
#     def id(self) -> int:
#     def parents(self) -> List[int]:
#     def add(self, node: _Node):
#     def get_by_id(self, user_id: int) -> _Node:
#     def is_id_exists(self, user_id: int):
#     def nodes(self) -> List[_Node]:
# def _build_tree(root_id: int, max_depth: SupportsInt) -> _Tree:
#     def add_next_level(prev_level: List[int], depth: int, parents: List[int]):
# def _find_common_friend(root_id: int, tree: _Tree,
#                         max_depth: SupportsInt) -> Optional[List[int]]:
#     def check_next_level(prev_level: List[int], depth: int,
#                          parents: List[int]) -> Optional[List[int]]:
# def find_chain(user1: int, user2: int,
#                max_length: int = 5) -> Optional[List[int]]:
# 
# Path: app/services/mutual_friends.py
# def get_mutual_friends(user_id: int):
# 
# Path: app/services/temperature_map.py
# def calculate_color(value, interval_length):
# 
# Path: app/services/vk.py
# def get_user(user_id) -> User:
# def get_users(user_ids: Iterable[int]) -> List[User]:
# def get_friends_count(user_id: int) -> int:
# def get_friends(user_id: int) -> List[User]:
# def get_friends_ids(user_id: int) -> List[int]:
# def get_friends_ids_batch(user_ids: List[int]) -> List[List[int]]:
# def get_mutual_friends_ids(user1: int, user2: int) -> List[int]:
# def get_mutual_friends_ids_batch(user_ids: List[int],
#                                  my_id: int) -> Dict[int, List[int]]:


# Path: app/controllers/api.py
from flask import Blueprint, jsonify, request
from app.model import Chain, Response, Status, UsersGraph
from app.services import friends_chain, mutual_friends, temperature_map, vk



api = Blueprint('api', __name__)


@api.route("/api/user")
def get_user():
    user_id = request.args.get("userId")
    
    try:
        user = vk.get_user(user_id)

        if vk.get_friends_count(user.id) > 0: