import argparse
import random

from dmac.interface import AccountSDK


def main():
    parser = argparse.ArgumentParser(description="Darsman Account CLI")
    parser.add_argument(
        "service",
        choices=["login", "user", "wallet"],
        help="Service to test (login, user, wallet",
    )

    parser.add_argument(
        "operation",
        choices=["create", "get", "increase"],
        help="Operation to test (create, get)",
    )

    parser.add_argument("--token", help="Authorization token")
    parser.add_argument("--api_key", help="API KEY")

    args = parser.parse_args()

    try:
        response = None
        account_sdk = AccountSDK()
        if args.operation == "create":
            if args.service == "user":
                mobile = str(random.randint(10, 10000))
                response = account_sdk.create_account(
                    api_key=args.api_key,
                    mobile=mobile,
                    email=f"email-{mobile}@test.com",
                    password="password",
                    user_type="teacher",
                )
            if args.service == "wallet":
                response = account_sdk.create_wallet(
                    api_key=args.api_key, jwt_token=args.token
                )

            if args.service == "login":
                response = account_sdk.login(
                    api_key=args.api_key,
                    mobile="username",
                    password="password",
                )

        elif args.operation == "get":
            if args.service == "user":
                response = account_sdk.account(
                    api_key=args.api_key, jwt_token=args.token
                )

            if args.service == "wallet":
                response = account_sdk.wallet(
                    api_key=args.api_key, jwt_token=args.token
                )
        elif args.operation == "increase":
            if args.service == "wallet":
                response = account_sdk.increase_wallet(
                    api_key=args.api_key, jwt_token=args.token, amount="100_000"
                )
        print(response)

    except Exception as e:
        print(f"Error: {e}")


if __name__ == "__main__":
    main()
