#!/usr/bin/env python3
import gvaauthupdate
import argparse
import sys


class CDC:
    def __init__(self, args):
        self.args = args
        self.gau = gvaauthupdate.GvaAuthUpdate()
    def run(self):
        if self.args.e:
            auth_methods = self.gau.get_real_auth_methods()
            if "cdc" not in auth_methods:
                default_auth_methods = self.gau.get_ordered_default_auth_methods()
                final_auth_methods = []
                for x in default_auth_methods:
                    if x in auth_methods or x == "cdc":
                        final_auth_methods.append(x)
                self.gau.save_real_auth_methods(final_auth_methods)
        elif self.args.d:
            auth_methods = self.gau.get_real_auth_methods()
            if "cdc" in auth_methods:
                auth_methods.remove("cdc")
                self.gau.save_real_auth_methods(auth_methods)
        elif self.args.t:
            auth_methods = self.gau.get_real_auth_methods()
            if "cdc" in auth_methods:
                print("True")
                sys.exit(0)
            else:
                print("False")
                sys.exit(1)
        sys.exit(0)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-e", action="store_true", help="Enable CDC")
    parser.add_argument("-d", action="store_true", help="Disable CDC")
    parser.add_argument("-t", action="store_true", help="State of CDC")
    args = parser.parse_args()
    cdc = CDC(args)
    cdc.run()
