#!/usr/bin/python3

import sys

from lib.paheko import Paheko
from lib.ldap import Ldap

paheko = Paheko()
categorie_membres = paheko.get_categorie_id("Membres")
membres = paheko.get_users_in_categorie(categorie_membres)

def test_quota(paheko_entry, ldap_entry):
    ok = True
    quota_disque = paheko_entry["quota_disque"].strip("'")
    if f"{quota_disque}G".encode() != ldap_entry[1]['mailQuota'][0]:
        ok = False

    return ok

def test_mail_secours(paheko_entry, ldap_entry):
    try:
        if paheko_entry["email_secours"]:
            return paheko_entry["email_secours"].strip("'").encode() == ldap_entry[1]['mailDeSecours'][0]
        else:
            return False
    except e:
        print(paheko_entry)
        print(ldap_entry)
        raise e

with Ldap() as ldap:
    try:
        for membre in membres:
            ldap_entry = ldap.get_email(membre["email"])[0]

            ok = True

            #ok &= test_quota(membre, ldap_entry)
            ok &= test_mail_secours(membre, ldap_entry)

            if not ok:
                print(membre)
                print(ldap_entry)
                print()
    except Exception as e:
        print(membre)
        print(ldap.get_email(membre["email"]))
        raise e