# Path: isserviceup/services/models/service.py
# class Service(object):
# 
#     @property
#     def id(self):
#         return self.__class__.__name__
# 
#     @property
#     def status_url(self):
#         raise NotImplemented()
# 
#     @property
#     def icon_url(self):
#         raise NotImplemented()
# 
#     @property
#     def name(self):
#         raise NotImplemented()
# 
#     def get_status(self):
#         raise NotImplemented()
# 
# class Status(Enum):
#     ok = 1              # green
#     maintenance = 2     # blue
#     minor = 3           # yellow
#     major = 4           # orange
#     critical = 5        # red
#     unavailable = 6     # gray


import requests
from bs4 import BeautifulSoup
from isserviceup.services.models.service import Service, Status



class StatusPagePlugin(Service):

    def get_status(self):
        r = requests.get(self.status_url)
        b = BeautifulSoup(r.content, 'html.parser')
        page_status = b.find(class_=['status', 'index'])
        try:
            status = next(x for x in page_status.attrs['class'] if x.startswith('status-'))

            if status == 'status-none':
                return Status.ok
            elif status == 'status-critical':
                return Status.critical
            elif status == 'status-major':
                return Status.major
            elif status == 'status-minor':

# Path: isserviceup/services/models/service.py
# class Service(object):
# 
#     @property
#     def id(self):
#         return self.__class__.__name__
# 
#     @property
#     def status_url(self):
#         raise NotImplemented()
# 
#     @property
#     def icon_url(self):
#         raise NotImplemented()
# 
#     @property
#     def name(self):
#         raise NotImplemented()
# 
#     def get_status(self):
#         raise NotImplemented()
# 
# class Status(Enum):
#     ok = 1              # green
#     maintenance = 2     # blue
#     minor = 3           # yellow
#     major = 4           # orange
#     critical = 5        # red
#     unavailable = 6     # gray


# Path: isserviceup/services/models/statuspage.py
import requests
from bs4 import BeautifulSoup
from isserviceup.services.models.service import Service, Status




class StatusPagePlugin(Service):

    def get_status(self):
        r = requests.get(self.status_url)
        b = BeautifulSoup(r.content, 'html.parser')
        page_status = b.find(class_=['status', 'index'])
        try:
            status = next(x for x in page_status.attrs['class'] if x.startswith('status-'))

            if status == 'status-none':
                return Status.ok
            elif status == 'status-critical':
                return Status.critical
            elif status == 'status-major':
                return Status.major
            elif status == 'status-minor':

                return Status.minor