'''
Created on 21 lut 2020

@author: fpawlak
'''
from __future__ import print_function
from Classes.CodesysLibsScriptsException import CodesysLibsScriptsException
import sys


class LibraryRestrictions():
    def __init__(self, company, mustBeReleased):
        self.company = company
        self.mustBeReleased = mustBeReleased
        
    
    def checkName(self, project):
        print('Checking whether library name is does not start with __DEVELOP__', end='')
        sys.stdout.flush()
        
        if not project.title.startswith('__DEVELOP__ - '):
            print(' -> {} -> SUCCESS'.format(project.title))
        else:
            print(' -> {} -> ERROR'.format(project.title))
            raise WrongLibraryName(None)
        
    
    def checkDeveloper(self, project):
        print('Checking whether library company is valid', end='')
        sys.stdout.flush()
        
        if project.company == self.company:
            print(' -> SUCCESS -> {} = {}'.format(project.company, self.company))
        else:
            print(' -> ERROR -> {} != {}'.format(project.company, self.company))
            raise WrongLibraryDeveloper(None)
    
    
    def checkIsReleased(self, project):
        print('Checking whether project is marked as "RELEASED"', end='')
        sys.stdout.flush()
        
        if project.released:
            print(' -> RELEASED -> SUCCESS')
        else:
            if self.mustBeReleased:
                print(' -> NOT_RELEASED -> ERROR')
                raise LibraryNotReleased(None)
            else:
                print(' -> NOT_RELEASED -> OK')

        

class WrongLibraryName(CodesysLibsScriptsException):
    pass

class WrongLibraryDeveloper(CodesysLibsScriptsException):
    pass

class LibraryNotReleased(CodesysLibsScriptsException):
    pass