import argparse

from dmmc.interface import MediaSDK


def main():
    parser = argparse.ArgumentParser(description="Darsman Account CLI")
    parser.add_argument(
        "service",
        choices=["bucket", "media", "store_transaction"],
        help="bucket, media, store_transaction",
    )

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

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

    args = parser.parse_args()

    try:
        response = None
        media_sdk = MediaSDK(url=args.url if args.url else "127.0.0.1:50051")
        if args.service == "bucket":
            if args.operation == "create":
                response = media_sdk.create_bucket(api_key=args.api_key, name="tea")
            if args.operation == "validate":
                response = media_sdk.validate_bucket(
                    api_key=args.api_key, uuid_id="1865735e-3709-4371-b919-466207e556d1"
                )
            if args.operation == "get":
                response = media_sdk.bucket(
                    api_key=args.api_key, uuid_id="1865735e-3709-4371-b919-466207e556d1"
                )

        if args.service == "media":
            if args.operation == "create":
                response = media_sdk.create_media(
                    api_key=args.api_key,
                    file="interface.py",
                    file_name="inter",
                    extension="py",
                    file_size=1,
                    bucket="a8036291-a4ea-4d1e-aa82-116d15296490",
                    store_place_type="object_storage",
                )
            if args.operation == "validate":
                response = media_sdk.validate_media(
                    api_key=args.api_key, uuid_id="d11eea6c-cd0d-4faa-aed8-64b55cc2f8a8"
                )
            if args.operation == "get":
                response = media_sdk.media(
                    api_key=args.api_key, uuid_id="d11eea6c-cd0d-4faa-aed8-64b55cc2f8a8"
                )

        print(response)

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


if __name__ == "__main__":
    main()
