from minio_manager.bucket_handler import handle_bucket
from minio_manager.classes.config import ClusterResources
from minio_manager.policy_handler import handle_bucket_policy, handle_iam_policy, handle_iam_policy_attachments
from minio_manager.service_account_handler import handle_service_account
from minio_manager.utilities import logger


def handle_resources(resources: ClusterResources):
    """Handle the provided bucket, bucket policies, IAM policies, and user policy attachments, in that order.

    Args:
        resources: ClusterResources object with all resources
    """
    logger.info("Handling buckets...")
    for bucket in resources.buckets:
        handle_bucket(bucket)

    logger.info("Handling bucket policies...")
    for bucket_policy in resources.bucket_policies:
        handle_bucket_policy(bucket_policy)

    logger.info("Handling service accounts...")
    for service_account in resources.service_accounts:
        handle_service_account(service_account)

    logger.info("Handling IAM policies...")
    for iam_policy in resources.iam_policies:
        handle_iam_policy(iam_policy)

    logger.info("Handling IAM policy attachments...")
    for iam_policy_attachment in resources.iam_policy_attachments:
        handle_iam_policy_attachments(iam_policy_attachment)
