#!/usr/bin/python3 -u
# SPDX-FileCopyrightText: 2024-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

import argparse
import sys

from univention.admin.rest.client.__main__ import main
from univention.config_registry import ucr


parser = argparse.ArgumentParser()
parser.add_argument('--binddn')
parser.add_argument('--bindpwd')
parser.add_argument('--bindpwdfile')

replacements = {
    '--ignore_exists': '--ignore-exists',
    '--ignore_not_exists': '--ignore-not-exists',
    '--remove_referring': '--remove-referring',
}

sys.argv = [replacements.get(x, x) for x in sys.argv]

args, sys.argv = parser.parse_known_args(sys.argv)

if True:  # or ucr['server/role'] not in ('domaincontroller_master', 'domaincontroller_backup'):
    sys.argv.insert(1, '--binddn')
    sys.argv.insert(2, args.binddn or ucr['tests/domainadmin/account'])
    if args.bindpwdfile:
        sys.argv.insert(3, '--bindpwdfile')
        sys.argv.insert(4, args.bindpwdfile)
    else:
        sys.argv.insert(3, '--bindpwd')
        sys.argv.insert(4, args.bindpwd or ucr['tests/domainadmin/pwd'])

main()
