import requests

from ..Playbooks.Playbook import PlaybookCredentialCollection, FileCleanupTask
from ... import Configuration
from ...Logging.Logger import log, Severity
from ..SetupStep import SetupStep
from requests.auth import HTTPBasicAuth

class TestCustomerAccess(SetupStep):
    def __init__(self):
        super().__init__()

    def run(self, file_cleanup_stack : list[FileCleanupTask], credentials: PlaybookCredentialCollection) -> bool:
        basic = HTTPBasicAuth(credentials.mli, credentials.mli_password)
        url = f'https://{Configuration.get_val("repository", "server")}/customers/{credentials.mli}/license.ldif'
        response = requests.get(url, auth=basic)
        if response.status_code == 200:
            log(f"Login succeeded with {credentials.mli}")
            return True
        else:
            log(f"Login failed with {credentials.mli} - Status code: {response.status_code}", Severity.ERROR)
            return False