from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.workspaces.workspaces_client import (
    workspaces_client,
)


class workspaces_volume_encryption_enabled(Check):
    def execute(self):
        findings = []
        for workspace in workspaces_client.workspaces:
            report = Check_Report_AWS(metadata=self.metadata(), resource=workspace)
            report.status = "PASS"
            report.status_extended = f"WorkSpaces workspace {workspace.id} root and user volumes are encrypted."
            if not workspace.user_volume_encryption_enabled:
                report.status = "FAIL"
                report.status_extended = f"WorkSpaces workspace {workspace.id} with user unencrypted volumes."
            if not workspace.root_volume_encryption_enabled:
                report.status = "FAIL"
                report.status_extended = f"WorkSpaces workspace {workspace.id} with root unencrypted volumes."
            if (
                not workspace.root_volume_encryption_enabled
                and not workspace.user_volume_encryption_enabled
            ):
                report.status = "FAIL"
                report.status_extended = f"WorkSpaces workspace {workspace.id} with root and user unencrypted volumes."

            findings.append(report)
        return findings
