import ldap

class LdapConnectManager:
    def __init__(self, ldap_ip: str, ldap_domain: str):
        self.ldap_ip = ldap_ip
        self.ldap_domain = ldap_domain

    def establish_ldap_connection(self):
        try:
            ldap_connection = ldap.initialize(f"ldap://{self.ldap_ip}")
            print(ldap_connection)
            return "All good"
        except ldap.SERVER_DOWN:
            print("Cannot connect to LDAP server")
            return "Cannot connect to LDAP server"

    def user_authentication(self, username: str, password: str):
        ldap_connector = ldap.initialize(f"ldap://{self.ldap_ip}")
        try:
            ldap_connector.bind_s(f"dc=EPP,dc=RU,cn=vasya", password)
            ldap_result = ldap_connector.search("dc=EPP,dc=RU", ldap.SCOPE_SUBTREE, "(&(objectClass=Person)(cn=vasya))", None)
            res_type, data = ldap_connector.result(ldap_result, 0)
            print(f"\n\n\n\n\n\n\n\n\n\n{data}")
            return data
        except ldap.SERVER_DOWN:
            return "Server is offline"
        except ldap.INVALID_CREDENTIALS:
            return "Password is incorrect"