"""
SPDX-FileCopyrightText: 2022-present Intel Corporation
SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
SPDX-License-Identifier: Apache-2.0
"""

import sys
import requests
import json
# noinspection PyUnresolvedReferences
from requests.structures import CaseInsensitiveDict
import logging as log
from datetime import datetime

from device import Device


class Roc(object):

    def __init__(self, url, user, password, enterpriseId, siteId):
        self.url = url
        self.user = user
        self.password = password
        self.key = self.get_key()
        self.enterpriseId = enterpriseId
        self.siteId = siteId

        self.enterprise = None
        self.update()

    def headers(self):
        h = CaseInsensitiveDict()
        h["Content-Type"] = "application/json"
        h["Authorization"] = "Bearer " + self.key
        return h

    def get_key(self):
        url = "https://keycloak.opennetworking.org/auth/realms/master/protocol/openid-connect/token"
        headers = CaseInsensitiveDict()
        headers["Content-Type"] = "application/x-www-form-urlencoded"
        data = {
            'grant_type': 'password',
            'client_id': 'aether-roc-gui',
            'username': self.user,
            'password': self.password,
            'scope': 'openid profile email groups'
        }
        response = requests.post(url, data, headers)
        key = json.loads(response.text)['access_token']
        return key

    def update(self):
        url = self.url + "enterprises"
        response = requests.get(url, headers=self.headers())
        if response.status_code != 200:
            log.error("get_enterprise() failed, status_code: {}".format(response.status_code))
            return None

        result = json.loads(response.text)
        enterprises = result['enterprise']

        for enterprise in enterprises:
            for k, v in enterprise.items():
                if k == 'enterprise-id' and v == self.enterpriseId:
                    self.enterprise = enterprise

    def get_site(self):
        sites = self.enterprise['site']
        for site in sites:
            for k, v in site.items():
                if k == 'site-id' and v == self.siteId:
                    return site
        return None

    def devices(self):
        site = self.get_site()
        devices = site['device']
        for device in devices:
            yield device

    def get_imsi(self, simId):
        site = self.get_site()
        sims = site['sim-card']
        for sim in sims:
            if sim['sim-id'] == simId:
                return str(sim['imsi'])
        return None

    def update_devices(self, devices):
        self.update()
        new = {}
        for d in self.devices():
            imsi_id = str(d['device-id'])
            last_reachable = datetime.min
            imsi = self.get_imsi(d['sim-card'])
            if imsi_id in devices:
                last_reachable = devices[imsi_id].last_reachable
            new[imsi_id] = Device(imsi_id, imsi, last_reachable)
        return new


if __name__ == '__main__':
    url = "https://roc.menlo.aetherproject.org/aether-roc-api/aether/v2.0.0/connectivity-service-v2/"
    user = sys.argv[1]
    password = sys.argv[2]
    enterprise = 'aether-onf'
    site = 'menlo-4g'
    roc = Roc(url, user, password, enterprise, site)
    devices = roc.update_devices({})
    for device in devices.values():
        print(device)
