#  SPDX-FileCopyrightText: 2025 Greenbone AG
#
#  SPDX-License-Identifier: GPL-3.0-or-later

from collections.abc import Mapping, Sequence
from typing import Any

from gvm.protocols.gmp.requests import EntityID

from ...utils import SupportsStr
from .._protocol import T
from ._gmp227 import GMPv227
from .requests.next import (
    AgentGroups,
    AgentInstallerInstructionLanguageType,
    AgentInstallerInstructions,
    Agents,
    AliveTest,
    AuditReport,
    Credentials,
    CredentialStoreCredentialType,
    CredentialStores,
    IntegrationConfigs,
    OCIImageTargets,
    ReportApplications,
    ReportClosedCVEs,
    ReportCVEs,
    ReportErrors,
    ReportHosts,
    ReportOperatingSystems,
    ReportPorts,
    ReportTlsCertificates,
    ReportVulnerabilities,
    ScanReports,
    Targets,
    Tasks,
    WebApplicationTargets,
)
from .requests.v224 import AliveTest as AliveTestV224
from .requests.v224 import HostsOrdering
from .requests.v226 import ReportFormatType


class GMPNext(GMPv227[T]):
    """
    A class implementing the "Next" version of Greenbone Management Protocol (GMP)
    containing features that are not part of the stable release yet.

    These features may change at any time and may not be available in all builds
    of the gvmd back-end.

    Example:

        .. code-block:: python

            from gvm.protocols.gmp.next import GMP

            with GMP(connection) as gmp:
                resp = gmp.get_tasks()
    """

    @staticmethod
    def get_protocol_version() -> tuple[int, int]:
        return (22, 8)

    def get_agent_installer_instruction(
        self,
        *,
        scanner_id: EntityID,
        language_type: AgentInstallerInstructionLanguageType,
        origin_url: str,
    ) -> T:
        """Request an agent installer instruction.

        Args:
            scanner_id: UUID of the Agent controller to get the installer instruction for.
            language_type: Language of the installer instruction.
            origin_url: Origin URL used to generate the executable agent
                installation command.
        """
        return self._send_request_and_transform_response(
            AgentInstallerInstructions.get_agent_installer_instruction(
                scanner_id=scanner_id,
                language_type=language_type,
                origin_url=origin_url,
            )
        )

    def get_agents(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        details: bool | None = None,
    ) -> T:
        """Request a list of agents.

        Args:
            filter_string: Filter term to use for the query.
            filter_id: UUID of an existing filter to use for the query.
            details: Whether to include detailed agent info.
        """
        return self._send_request_and_transform_response(
            Agents.get_agents(
                filter_string=filter_string,
                filter_id=filter_id,
                details=details,
            )
        )

    def modify_agents(
        self,
        agent_ids: list[EntityID],
        *,
        authorized: bool | None = None,
        update_to_latest: bool | None = None,
        config: Mapping[str, Any] | None = None,
        comment: str | None = None,
    ) -> T:
        """
        Modify multiple agents.

        Args:
            agent_ids: List of agent UUIDs to modify.
            authorized: Whether the agent is authorized.
            update_to_latest: Whether the agent is allowed to update to latest automatically.
            config: Nested config for Agent Controller.
            comment: Optional comment for the change.
        """
        return self._send_request_and_transform_response(
            Agents.modify_agents(
                agent_ids=agent_ids,
                authorized=authorized,
                update_to_latest=update_to_latest,
                config=config,
                comment=comment,
            )
        )

    def delete_agents(self, agent_ids: list[EntityID]) -> T:
        """Delete multiple agents

        Args:
            agent_ids: List of agent UUIDs to delete
        """
        return self._send_request_and_transform_response(
            Agents.delete_agents(agent_ids=agent_ids)
        )

    def modify_agent_control_scan_config(
        self,
        agent_control_id: EntityID,
        config: Mapping[str, Any],
    ) -> T:
        """
        Modify agent control scan config.

        Args:
            agent_control_id: The agent control UUID.
            config: Nested config for Agent Controller.
        """
        return self._send_request_and_transform_response(
            Agents.modify_agent_control_scan_config(
                agent_control_id=agent_control_id,
                config_defaults=config,
            )
        )

    def get_agent_groups(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        trash: bool | None = None,
    ) -> T:
        """Request a list of agent groups.

        Args:
            filter_string: Filter expression to use.
            filter_id: UUID of a predefined filter.
            trash: If True, return trashed agent groups.

        Returns:
            Request object to fetch agent groups.
        """
        return self._send_request_and_transform_response(
            AgentGroups.get_agent_groups(
                filter_string=filter_string,
                filter_id=filter_id,
                trash=trash,
            )
        )

    def get_agent_group(self, agent_group_id: EntityID) -> T:
        """Request a single agent group by ID.

        Args:
            agent_group_id: UUID of the agent group.

        Raises:
            RequiredArgument: If agent_group_id is not provided.

        Returns:
            Request object to fetch the specific agent group.
        """
        return self._send_request_and_transform_response(
            AgentGroups.get_agent_group(
                agent_group_id=agent_group_id,
            )
        )

    def create_agent_group(
        self,
        name: str,
        agent_ids: list[str],
        scheduler_cron_time: str,
        *,
        comment: str | None = None,
    ) -> T:
        """Create a new agent group.

        Args:
            name: Name of the new agent group.
            agent_ids: List of agent UUIDs to include in the group (required).
            scheduler_cron_time: Scheduler cron to use.
            comment: Optional comment for the group.

        Raises:
            RequiredArgument: If name or agent_ids is not provided.
        """
        return self._send_request_and_transform_response(
            AgentGroups.create_agent_group(
                name=name,
                comment=comment,
                agent_ids=agent_ids,
                scheduler_cron_time=scheduler_cron_time,
            )
        )

    def modify_agent_group(
        self,
        agent_group_id: EntityID,
        scheduler_cron_time: str,
        *,
        name: str | None = None,
        comment: str | None = None,
        agent_ids: list[str] | None = None,
    ) -> T:
        """Modify an existing agent group.

        Args:
            agent_group_id: UUID of the group to modify.
            name: Optional new name for the group.
            scheduler_cron_time: Scheduler cron to use.
            comment: Optional comment for the group.
            agent_ids: Optional list of agent UUIDs to set for the group.

        Raises:
            RequiredArgument: If agent_group_id is not provided.
        """
        return self._send_request_and_transform_response(
            AgentGroups.modify_agent_group(
                agent_group_id=agent_group_id,
                name=name,
                comment=comment,
                agent_ids=agent_ids,
                scheduler_cron_time=scheduler_cron_time,
            )
        )

    def delete_agent_group(
        self,
        agent_group_id: EntityID,
        ultimate: bool = False,
    ) -> T:
        """Delete an existing agent group.

        Args:
            agent_group_id: UUID of the group to delete.
            ultimate: Whether to permanently delete or move to trashcan.

        Raises:
            RequiredArgument: If agent_group_id is not provided.
        """
        return self._send_request_and_transform_response(
            AgentGroups.delete_agent_group(
                agent_group_id=agent_group_id,
                ultimate=ultimate,
            )
        )

    def clone_agent_group(
        self,
        agent_group_id: EntityID,
    ) -> T:
        """Clone an existing agent group

        Args:
            agent_group_id: UUID of an existing agent group to clone from

        Returns:
            Request: GMP command to create a new agent group based on a copy
        """
        return self._send_request_and_transform_response(
            AgentGroups.clone_agent_group(agent_group_id)
        )

    def sync_agents(self) -> T:
        """Trigger agents synchronization from all agent controllers."""
        return self._send_request_and_transform_response(Agents.sync_agents())

    def get_agent_support_bundle(
        self,
        agent_id: EntityID,
        days: int = 0,
    ) -> T:
        """Request a support bundle for an agent.

        Args:
            agent_id: ID of the agent to get the support bundle for.
            days: Number of days of logs to include. If None, zero is sent so the
                Agent Controller uses its configured default.

        Raises:
            RequiredArgument: If agent_id is missing.
            ValueError: If days is negative.
        """
        return self._send_request_and_transform_response(
            Agents.get_agent_support_bundle(
                agent_id,
                days=days,
            )
        )

    def create_credential_store_credential(
        self,
        name: str,
        credential_type: CredentialStoreCredentialType | str,
        *,
        comment: str | None = None,
        credential_store_id: EntityID | None = None,
        vault_id: str | None = None,
        host_identifier: str | None = None,
    ) -> T:
        """Create a new credential store type credential

        Args:
            name: Name of the credential
            credential_type: Type of the credential
            comment: Optional comment for the credential object
            credential_store_id: Optional credential store id to fetch the credential from
            vault_id: Vault id used to fetch the credential from credential store
            host_identifier: Host identifier used to fetch the credential from credential store
        """
        return self._send_request_and_transform_response(
            Credentials.create_credential_store_credential(
                name=name,
                credential_type=credential_type,
                comment=comment,
                credential_store_id=credential_store_id,
                vault_id=vault_id,
                host_identifier=host_identifier,
            )
        )

    def modify_credential_store_credential(
        self,
        credential_id: EntityID,
        *,
        name: str | None = None,
        comment: str | None = None,
        credential_store_id: EntityID | None = None,
        vault_id: str | None = None,
        host_identifier: str | None = None,
    ) -> T:
        """Modify an existing credential stored in a credential store

        Args:
            credential_id: UUID of the credential to modify
            name: Name of the credential
            comment: Optional comment for the credential object
            credential_store_id: Optional credential store id to fetch the credential from
            vault_id: Vault id used to fetch the credential from credential store
            host_identifier: Host identifier used to fetch the credential from credential store
        """
        return self._send_request_and_transform_response(
            Credentials.modify_credential_store_credential(
                credential_id=credential_id,
                name=name,
                comment=comment,
                credential_store_id=credential_store_id,
                vault_id=vault_id,
                host_identifier=host_identifier,
            )
        )

    def get_credential_store(
        self,
        credential_store_id: EntityID,
        *,
        details: bool | None = None,
    ) -> T:
        """Request a credential store

        Args:
            credential_store_id: ID of credential store to fetch
            details: True to request all details
        """
        return self._send_request_and_transform_response(
            CredentialStores.get_credential_store(
                credential_store_id=credential_store_id,
                details=details,
            )
        )

    def get_credential_stores(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        details: bool | None = None,
    ) -> T:
        """Request a list of credential stores

        Args:
            filter_string: Filter term to use for the query
            filter_id: UUID of an existing filter to use for the query
            details: True to request all details
        """
        return self._send_request_and_transform_response(
            CredentialStores.get_credential_stores(
                filter_string=filter_string,
                filter_id=filter_id,
                details=details,
            )
        )

    def modify_credential_store(
        self,
        credential_store_id: EntityID,
        *,
        active: bool | None = None,
        host: str | None = None,
        port: int | None = None,
        path: str | None = None,
        app_id: str | None = None,
        client_cert: str | None = None,
        client_key: str | None = None,
        client_pkcs12_file: str | None = None,
        passphrase: str | None = None,
        server_ca_cert: str | None = None,
        comment: str | None = None,
    ) -> T:
        """Modify an existing credential store

        Args:
            credential_store_id: ID of credential store to fetch
            active: Whether the credential store is active
            host: The host to use for reaching the credential store
            port: The port to use for reaching the credential store
            path: The URI path the credential store is using
            app_id: Depends on the credential store used. Usually called the same in the credential store
            client_cert: The client certificate to use for authorization, as a plain string
            client_key: The client key to use for authorization, as a plain string
            client_pkcs12_file: The pkcs12 file contents to use for authorization, as a plain string
                (alternative to using client_cert and client_key)
            passphrase: The passphrase to use to decrypt client_pkcs12_file or client_key file
            server_ca_cert: The server certificate, so the credential store can be trusted
            comment: An optional comment to store alongside the credential store
        """
        return self._send_request_and_transform_response(
            CredentialStores.modify_credential_store(
                credential_store_id=credential_store_id,
                active=active,
                host=host,
                port=port,
                path=path,
                app_id=app_id,
                client_cert=client_cert,
                client_key=client_key,
                client_pkcs12_file=client_pkcs12_file,
                passphrase=passphrase,
                server_ca_cert=server_ca_cert,
                comment=comment,
            )
        )

    def verify_credential_store(
        self,
        credential_store_id: EntityID,
    ) -> T:
        """Verify that the connection to an existing credential store works

        Args:
            credential_store_id: The uuid of the credential store to verify
        """
        return self._send_request_and_transform_response(
            CredentialStores.verify_credential_store(
                credential_store_id=credential_store_id,
            )
        )

    def create_oci_image_target(
        self,
        name: str,
        image_references: list[str],
        *,
        comment: str | None = None,
        credential_id: EntityID | None = None,
    ) -> T:
        """Create a new OCI image target

        Args:
            name: Name of the OCI image target
            image_references: List of OCI image URLs to scan
            comment: Comment for the target
            credential_id: UUID of a credential to use on target
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.create_oci_image_target(
                name=name,
                image_references=image_references,
                comment=comment,
                credential_id=credential_id,
            )
        )

    def modify_oci_image_target(
        self,
        oci_image_target_id: EntityID,
        *,
        name: str | None = None,
        comment: str | None = None,
        image_references: list[str] | None = None,
        credential_id: EntityID | None = None,
    ) -> T:
        """Modify an existing OCI image target.

        Args:
            oci_image_target_id: UUID of target to modify.
            comment: Comment on target.
            name: Name of target.
            image_references: List of OCI image URLs to scan.
            credential_id: UUID of credential to use on target.
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.modify_oci_image_target(
                oci_image_target_id,
                name=name,
                comment=comment,
                image_references=image_references,
                credential_id=credential_id,
            )
        )

    def clone_oci_image_target(self, oci_image_target_id: EntityID) -> T:
        """Clone an existing OCI image target.

        Args:
            oci_image_target_id: UUID of an existing OCI image target to clone.
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.clone_oci_image_target(oci_image_target_id)
        )

    def delete_oci_image_target(
        self, oci_image_target_id: EntityID, *, ultimate: bool | None = False
    ) -> T:
        """Delete an existing OCI image target.

        Args:
            oci_image_target_id: UUID of an existing OCI image target to delete.
            ultimate: Whether to remove entirely or to the trashcan.
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.delete_oci_image_target(
                oci_image_target_id, ultimate=ultimate
            )
        )

    def get_oci_image_target(
        self, oci_image_target_id: EntityID, *, tasks: bool | None = None
    ) -> T:
        """Request a single OCI image target.

        Args:
            oci_image_target_id: UUID of the OCI image target to request.
            tasks: Whether to include list of tasks that use the target
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.get_oci_image_target(
                oci_image_target_id, tasks=tasks
            )
        )

    def get_oci_image_targets(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        trash: bool | None = None,
        tasks: bool | None = None,
    ) -> T:
        """Request a list of OCI image targets.

        Args:
            filter_string: Filter term to use for the query.
            filter_id: UUID of an existing filter to use for the query.
            trash: Whether to include targets in the trashcan.
            tasks: Whether to include list of tasks that use the target.
        """
        return self._send_request_and_transform_response(
            OCIImageTargets.get_oci_image_targets(
                filter_string=filter_string,
                filter_id=filter_id,
                trash=trash,
                tasks=tasks,
            )
        )

    def clone_task(self, task_id: EntityID) -> T:
        """Clone an existing task

        Args:
            task_id: UUID of existing task to clone from
        """
        return self._send_request_and_transform_response(
            Tasks.clone_task(task_id)
        )

    def create_agent_group_task(
        self,
        name: str,
        agent_group_id: EntityID,
        scanner_id: EntityID,
        *,
        comment: str | None = None,
        alterable: bool | None = None,
        schedule_id: EntityID | None = None,
        alert_ids: Sequence[EntityID] | None = None,
        schedule_periods: int | None = None,
        observers: Sequence[str] | None = None,
        preferences: Mapping[str, SupportsStr] | None = None,
    ) -> T:
        """Create a new scan task using an agent group.

        Args:
            name: Name of the new task.
            agent_group_id: UUID of the agent group to be scanned.
            scanner_id: UUID of scanner to use for scanning the agents.
            comment: Optional comment for the task.
            alterable: Whether the task should be alterable.
            alert_ids: List of UUIDs for alerts to be applied to the task.
            schedule_id: UUID of a schedule when the task should be run.
            schedule_periods: Limit to number of scheduled runs, 0 for unlimited.
            observers: List of usernames or IDs allowed to observe the task.
            preferences: Scanner preferences as name/value pairs.
        """
        return self._send_request_and_transform_response(
            Tasks.create_agent_group_task(
                name=name,
                agent_group_id=agent_group_id,
                scanner_id=scanner_id,
                comment=comment,
                alterable=alterable,
                schedule_id=schedule_id,
                alert_ids=alert_ids,
                schedule_periods=schedule_periods,
                observers=observers,
                preferences=preferences,
            )
        )

    def create_container_image_task(
        self,
        name: str,
        oci_image_target_id: EntityID,
        scanner_id: EntityID,
        *,
        comment: str | None = None,
        alterable: bool | None = None,
        schedule_id: EntityID | None = None,
        alert_ids: Sequence[EntityID] | None = None,
        schedule_periods: int | None = None,
        observers: Sequence[str] | None = None,
        preferences: Mapping[str, SupportsStr] | None = None,
    ) -> T:
        """Create a new scan task using an OCI image target.

        Args:
            name: Name of the new task.
            oci_image_target_id: UUID of the OCI image target to be scanned.
            scanner_id: UUID of scanner to use for scanning the agents.
            comment: Optional comment for the task.
            alterable: Whether the task should be alterable.
            alert_ids: List of UUIDs for alerts to be applied to the task.
            schedule_id: UUID of a schedule when the task should be run.
            schedule_periods: Limit to number of scheduled runs, 0 for unlimited.
            observers: List of usernames or IDs allowed to observe the task.
            preferences: Scanner preferences as name/value pairs.
        """
        return self._send_request_and_transform_response(
            Tasks.create_container_image_task(
                name=name,
                oci_image_target_id=oci_image_target_id,
                scanner_id=scanner_id,
                comment=comment,
                alterable=alterable,
                schedule_id=schedule_id,
                alert_ids=alert_ids,
                schedule_periods=schedule_periods,
                observers=observers,
                preferences=preferences,
            )
        )

    def create_import_task(self, name: str, *, comment: str | None = None) -> T:
        """Create a new import task

        An import task is a "meta" task to import and view reports from other
        systems.

        Args:
            name: Name of the task
            comment: Comment for the task
        """
        return self._send_request_and_transform_response(
            Tasks.create_import_task(name=name, comment=comment)
        )

    def create_container_task(
        self, name: str, *, comment: str | None = None
    ) -> T:
        """[DEPRECATED] Use create_import_task instead.

        This method will be removed in a future version.
        """
        return self._send_request_and_transform_response(
            Tasks.create_container_task(name=name, comment=comment)
        )

    def create_web_application_task(
        self,
        name: str,
        web_application_target_id: EntityID,
        scanner_id: EntityID,
        *,
        comment: str | None = None,
        alterable: bool | None = None,
        schedule_id: EntityID | None = None,
        alert_ids: Sequence[EntityID] | None = None,
        schedule_periods: int | None = None,
        observers: Sequence[str] | None = None,
        preferences: Mapping[str, SupportsStr] | None = None,
    ) -> T:
        """Create a new scan task using a web application target.

        Args:
            name: Name of the new task.
            web_application_target_id: UUID of the web application target to be scanned.
            scanner_id: UUID of scanner to use for scanning the agents.
            comment: Optional comment for the task.
            alterable: Whether the task should be alterable.
            alert_ids: List of UUIDs for alerts to be applied to the task.
            schedule_id: UUID of a schedule when the task should be run.
            schedule_periods: Limit to number of scheduled runs, 0 for unlimited.
            observers: List of usernames or IDs allowed to observe the task.
            preferences: Scanner preferences as name/value pairs.
        """
        return self._send_request_and_transform_response(
            Tasks.create_web_application_task(
                name=name,
                web_application_target_id=web_application_target_id,
                scanner_id=scanner_id,
                comment=comment,
                alterable=alterable,
                schedule_id=schedule_id,
                alert_ids=alert_ids,
                schedule_periods=schedule_periods,
                observers=observers,
                preferences=preferences,
            )
        )

    def create_task(
        self,
        name: str,
        config_id: EntityID,
        target_id: EntityID,
        scanner_id: EntityID,
        *,
        alterable: bool | None = None,
        hosts_ordering: HostsOrdering | None = None,
        schedule_id: EntityID | None = None,
        alert_ids: Sequence[EntityID] | None = None,
        comment: str | None = None,
        schedule_periods: int | None = None,
        observers: Sequence[str] | None = None,
        preferences: Mapping[str, SupportsStr] | None = None,
    ) -> T:
        """Create a new scan task

        Args:
            name: Name of the new task
            config_id: UUID of config to use by the task
            target_id: UUID of target to be scanned
            scanner_id: UUID of scanner to use for scanning the target
            comment: Comment for the task
            alterable: Whether the task should be alterable
            alert_ids: List of UUIDs for alerts to be applied to the task
            hosts_ordering: The order hosts are scanned in
            schedule_id: UUID of a schedule when the task should be run.
            schedule_periods: A limit to the number of times the task will be
                scheduled, or 0 for no limit
            observers: List of names or ids of users which should be allowed to
                observe this task
            preferences: Name/Value pairs of scanner preferences.
        """
        return self._send_request_and_transform_response(
            Tasks.create_task(
                name=name,
                config_id=config_id,
                target_id=target_id,
                scanner_id=scanner_id,
                alterable=alterable,
                hosts_ordering=hosts_ordering,
                schedule_id=schedule_id,
                alert_ids=alert_ids,
                comment=comment,
                schedule_periods=schedule_periods,
                observers=observers,
                preferences=preferences,
            )
        )

    def delete_task(
        self, task_id: EntityID, *, ultimate: bool | None = False
    ) -> T:
        """Deletes an existing task

        Args:
            task_id: UUID of the task to be deleted.
            ultimate: Whether to remove entirely, or to the trashcan.
        """
        return self._send_request_and_transform_response(
            Tasks.delete_task(task_id=task_id, ultimate=ultimate)
        )

    def get_tasks(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        trash: bool | None = None,
        details: bool | None = None,
        schedules_only: bool | None = None,
        ignore_pagination: bool | None = None,
    ) -> T:
        """Request a list of tasks

        Args:
            filter_string: Filter term to use for the query
            filter_id: UUID of an existing filter to use for the query
            trash: Whether to get the trashcan tasks instead
            details: Whether to include full task details
            schedules_only: Whether to only include id, name and schedule
                details
            ignore_pagination: Whether to ignore pagination settings (filter
                terms "first" and "rows"). Default is False.
        """
        return self._send_request_and_transform_response(
            Tasks.get_tasks(
                filter_string=filter_string,
                filter_id=filter_id,
                trash=trash,
                details=details,
                schedules_only=schedules_only,
                ignore_pagination=ignore_pagination,
            )
        )

    def get_task(self, task_id: EntityID) -> T:
        """Request a single task

        Args:
            task_id: UUID of an existing task
        """
        return self._send_request_and_transform_response(
            Tasks.get_task(task_id=task_id)
        )

    def modify_task(
        self,
        task_id: EntityID,
        *,
        name: str | None = None,
        config_id: EntityID | None = None,
        target_id: EntityID | None = None,
        scanner_id: EntityID | None = None,
        agent_group_id: EntityID | None = None,
        oci_image_target_id: EntityID | None = None,
        web_application_target_id: EntityID | None = None,
        alterable: bool | None = None,
        hosts_ordering: HostsOrdering | None = None,
        schedule_id: EntityID | None = None,
        schedule_periods: int | None = None,
        comment: str | None = None,
        alert_ids: Sequence[EntityID] | None = None,
        observers: Sequence[str] | None = None,
        preferences: Mapping[str, SupportsStr] | None = None,
    ) -> T:
        """Modifies an existing task.

        Args:
            task_id: UUID of task to modify.
            name: The name of the task.
            config_id: UUID of scan config to use by the task
            target_id: UUID of target to be scanned
            scanner_id: UUID of scanner to use for scanning the target
            agent_group_id: UUID of agent group to use for scanning
            oci_image_target_id: UUID of the OCI Image target to be scanned.
            web_application_target_id: UUID of the web application target to be scanned.
            comment: The comment on the task.
            alert_ids: List of UUIDs for alerts to be applied to the task
            hosts_ordering: The order hosts are scanned in
            schedule_id: UUID of a schedule when the task should be run.
            schedule_periods: A limit to the number of times the task will be
                scheduled, or 0 for no limit.
            observers: List of names or ids of users which should be allowed to
                observe this task
            preferences: Name/Value pairs of scanner preferences.
        """
        return self._send_request_and_transform_response(
            Tasks.modify_task(
                task_id=task_id,
                name=name,
                config_id=config_id,
                target_id=target_id,
                scanner_id=scanner_id,
                agent_group_id=agent_group_id,
                oci_image_target_id=oci_image_target_id,
                web_application_target_id=web_application_target_id,
                alterable=alterable,
                hosts_ordering=hosts_ordering,
                schedule_id=schedule_id,
                alert_ids=alert_ids,
                comment=comment,
                schedule_periods=schedule_periods,
                observers=observers,
                preferences=preferences,
            )
        )

    def move_task(
        self, task_id: EntityID, *, slave_id: EntityID | None = None
    ) -> T:
        """Move an existing task to another GMP slave scanner or the master

        Args:
            task_id: UUID of the task to be moved
            slave_id: UUID of the sensor to reassign the task to, empty for master.
        """
        return self._send_request_and_transform_response(
            Tasks.move_task(
                task_id=task_id,
                slave_id=slave_id,
            )
        )

    def start_task(self, task_id: EntityID) -> T:
        """Start an existing task

        Args:
            task_id: UUID of the task to be started
        """
        return self._send_request_and_transform_response(
            Tasks.start_task(task_id=task_id)
        )

    def resume_task(self, task_id: EntityID) -> T:
        """Resume an existing stopped task

        Args:
            task_id: UUID of the task to be resumed
        """
        return self._send_request_and_transform_response(
            Tasks.resume_task(task_id=task_id)
        )

    def stop_task(self, task_id: EntityID) -> T:
        """Stop an existing running task

        Args:
            task_id: UUID of the task to be stopped
        """
        return self._send_request_and_transform_response(
            Tasks.stop_task(task_id=task_id)
        )

    def get_integration_config(
        self, integration_config_id: EntityID, *, details: bool | None = None
    ) -> T:
        """Request a single Integration Configuration.

        Args:
           integration_config_id: UUID of the integration config to request.
           details: Whether to include detail information.
        """
        return self._send_request_and_transform_response(
            IntegrationConfigs.get_integration_config(
                integration_config_id=integration_config_id, details=details
            )
        )

    def get_integration_configs(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
    ) -> T:
        """Request a list of Integration Configurations.

        Args:
            filter_string: Filter term to use for the query.
            filter_id: UUID of an existing filter to use for the query.
        """
        return self._send_request_and_transform_response(
            IntegrationConfigs.get_integration_configs(
                filter_string=filter_string,
                filter_id=filter_id,
            )
        )

    def modify_integration_config(
        self,
        integration_config_id: EntityID,
        *,
        service_url: str | None = None,
        service_cacert: str | None = None,
        oidc_provider_url: str | None = None,
        oidc_provider_client_id: str | None = None,
        oidc_provider_client_secret: str | None = None,
    ) -> T:
        """Modify an existing Integration Configuration.

        Args:
            integration_config_id: UUID of configuration to modify.
            service_url: Integration Service URL.
            service_cacert: Integration Service Certificate.
            oidc_provider_url: OIDC Provider URL.
            oidc_provider_client_id: OIDC Provider Client ID.
            oidc_provider_client_secret: OIDC Provider Client Secret.
        """
        return self._send_request_and_transform_response(
            IntegrationConfigs.modify_integration_config(
                integration_config_id=integration_config_id,
                service_url=service_url,
                service_cacert=service_cacert,
                oidc_provider_url=oidc_provider_url,
                oidc_provider_client_id=oidc_provider_client_id,
                oidc_provider_client_secret=oidc_provider_client_secret,
            )
        )

    def get_report_hosts(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request hosts of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report host information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportHosts.get_report_hosts(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_audit_report_hosts(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request hosts of a single audit report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report host information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportHosts.get_audit_report_hosts(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_operating_systems(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request operating systems of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report operating system information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportOperatingSystems.get_report_operating_systems(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_ports(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request ports of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report port information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportPorts.get_report_ports(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_tls_certificates(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request TLS certificates of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report TLS certificate information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportTlsCertificates.get_report_tls_certificates(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_applications(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request applications of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report application information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportApplications.get_report_applications(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_cves(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request CVEs of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report CVE information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportCVEs.get_report_cves(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_closed_cves(
        self,
        report_id: EntityID,
        *,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request closed CVEs of a single report.

        Args:
            report_id: UUID of an existing report.
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report closed CVE information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportClosedCVEs.get_report_closed_cves(
                report_id=report_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_errors(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request errors of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report error information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportErrors.get_report_errors(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def get_report_vulnerabilities(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request vulnerabilities of a single report.

        Args:
            report_id: UUID of an existing report.
            filter_string: Filter term to use to filter results in the report
            filter_id: UUID of filter to use to filter results in the report
            ignore_pagination: Whether to ignore the filter terms "first" and
                "rows".
            details: Request additional report vulnerability information details.
                Defaults to True.
        """
        return self._send_request_and_transform_response(
            ReportVulnerabilities.get_report_vulnerabilities(
                report_id=report_id,
                filter_string=filter_string,
                filter_id=filter_id,
                ignore_pagination=ignore_pagination,
                details=details,
            )
        )

    def create_web_application_target(
        self,
        name: str,
        urls: list[str],
        *,
        comment: str | None = None,
        exclude_urls: list[str] | None = None,
        credential_id: EntityID | None = None,
    ) -> T:
        """Create a new web application target.

        Args:
            name: Name of the web application target.
            urls: List of URLs to scan.
            comment: Comment for the target.
            exclude_urls: List of URLs to exclude from the scan.
            credential_id: UUID of a credential to use on target.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.create_web_application_target(
                name=name,
                urls=urls,
                comment=comment,
                exclude_urls=exclude_urls,
                credential_id=credential_id,
            )
        )

    def modify_web_application_target(
        self,
        web_application_target_id: EntityID,
        *,
        name: str | None = None,
        comment: str | None = None,
        urls: list[str] | None = None,
        exclude_urls: list[str] | None = None,
        credential_id: EntityID | None = None,
    ) -> T:
        """Modify an existing web application target.

        Args:
            web_application_target_id: UUID of target to modify.
            name: Name of target.
            comment: Comment on target.
            urls: List of URLs to scan.
            exclude_urls: List of URLs to exclude from the scan.
            credential_id: UUID of credential to use on target.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.modify_web_application_target(
                web_application_target_id,
                name=name,
                comment=comment,
                urls=urls,
                exclude_urls=exclude_urls,
                credential_id=credential_id,
            )
        )

    def clone_web_application_target(
        self, web_application_target_id: EntityID
    ) -> T:
        """Clone an existing web application target.

        Args:
            web_application_target_id: UUID of an existing web application target to clone.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.clone_web_application_target(
                web_application_target_id
            )
        )

    def delete_web_application_target(
        self,
        web_application_target_id: EntityID,
        *,
        ultimate: bool | None = False,
    ) -> T:
        """Delete an existing web application target.

        Args:
            web_application_target_id: UUID of an existing web application target to delete.
            ultimate: Whether to remove entirely or to the trashcan.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.delete_web_application_target(
                web_application_target_id,
                ultimate=ultimate,
            )
        )

    def get_web_application_target(
        self,
        web_application_target_id: EntityID,
        *,
        tasks: bool | None = None,
    ) -> T:
        """Request a single web application target.

        Args:
            web_application_target_id: UUID of the web application target to request.
            tasks: Whether to include list of tasks that use the target.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.get_web_application_target(
                web_application_target_id,
                tasks=tasks,
            )
        )

    def get_web_application_targets(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        trash: bool | None = None,
        tasks: bool | None = None,
    ) -> T:
        """Request a list of web application targets.

        Args:
            filter_string: Filter term to use for the query.
            filter_id: UUID of an existing filter to use for the query.
            trash: Whether to include targets in the trashcan.
            tasks: Whether to include list of tasks that use the target.
        """
        return self._send_request_and_transform_response(
            WebApplicationTargets.get_web_application_targets(
                filter_string=filter_string,
                filter_id=filter_id,
                trash=trash,
                tasks=tasks,
            )
        )

    def create_target(
        self,
        name: str,
        *,
        asset_hosts_filter: str | None = None,
        hosts: list[str] | None = None,
        comment: str | None = None,
        exclude_hosts: list[str] | None = None,
        ssh_credential_id: EntityID | None = None,
        ssh_credential_port: int | str | None = None,
        smb_credential_id: EntityID | None = None,
        esxi_credential_id: EntityID | None = None,
        snmp_credential_id: EntityID | None = None,
        alive_test: str | AliveTest | AliveTestV224 | None = None,
        allow_simultaneous_ips: bool | None = None,
        reverse_lookup_only: bool | None = None,
        reverse_lookup_unify: bool | None = None,
        port_range: str | None = None,
        port_list_id: EntityID | None = None,
    ) -> T:
        """Create a new target

        Args:
            name: Name of the target
            asset_hosts_filter: Filter to select target host from assets hosts
            hosts: List of hosts addresses to scan
            exclude_hosts: List of hosts addresses to exclude from scan
            comment: Comment for the target
            ssh_credential_id: UUID of a ssh credential to use on target
            ssh_credential_port: The port to use for ssh credential
            smb_credential_id: UUID of a smb credential to use on target
            snmp_credential_id: UUID of a snmp credential to use on target
            esxi_credential_id: UUID of a esxi credential to use on target
            alive_test: Which alive test to use
            allow_simultaneous_ips: Whether to scan multiple IPs of the
                same host simultaneously
            reverse_lookup_only: Whether to scan only hosts that have names
            reverse_lookup_unify: Whether to scan only one IP when multiple IPs
                have the same name.
            port_range: Port range for the target
            port_list_id: UUID of the port list to use on target
        """
        return self._send_request_and_transform_response(
            Targets.create_target(
                name,
                asset_hosts_filter=asset_hosts_filter,
                hosts=hosts,
                comment=comment,
                exclude_hosts=exclude_hosts,
                ssh_credential_id=ssh_credential_id,
                ssh_credential_port=ssh_credential_port,
                smb_credential_id=smb_credential_id,
                esxi_credential_id=esxi_credential_id,
                snmp_credential_id=snmp_credential_id,
                alive_test=alive_test,
                allow_simultaneous_ips=allow_simultaneous_ips,
                reverse_lookup_only=reverse_lookup_only,
                reverse_lookup_unify=reverse_lookup_unify,
                port_range=port_range,
                port_list_id=port_list_id,
            )
        )

    def modify_target(
        self,
        target_id: EntityID,
        *,
        name: str | None = None,
        comment: str | None = None,
        hosts: list[str] | None = None,
        exclude_hosts: list[str] | None = None,
        ssh_credential_id: EntityID | None = None,
        ssh_credential_port: str | int | None = None,
        smb_credential_id: EntityID | None = None,
        esxi_credential_id: EntityID | None = None,
        snmp_credential_id: EntityID | None = None,
        alive_test: str | AliveTest | AliveTestV224 | None = None,
        allow_simultaneous_ips: bool | None = None,
        reverse_lookup_only: bool | None = None,
        reverse_lookup_unify: bool | None = None,
        port_list_id: EntityID | None = None,
    ) -> T:
        """Modify an existing target.

        Args:
            target_id: UUID of target to modify.
            comment: Comment on target.
            name: Name of target.
            hosts: List of target hosts.
            exclude_hosts: A list of hosts to exclude.
            ssh_credential_id: UUID of SSH credential to use on target.
            ssh_credential_port: The port to use for ssh credential
            smb_credential_id: UUID of SMB credential to use on target.
            esxi_credential_id: UUID of ESXi credential to use on target.
            snmp_credential_id: UUID of SNMP credential to use on target.
            port_list_id: UUID of port list describing ports to scan.
            alive_test: Which alive tests to use.
            allow_simultaneous_ips: Whether to scan multiple IPs of the
                same host simultaneously
            reverse_lookup_only: Whether to scan only hosts that have names.
            reverse_lookup_unify: Whether to scan only one IP when multiple IPs
                have the same name.
        """
        return self._send_request_and_transform_response(
            Targets.modify_target(
                target_id,
                name=name,
                comment=comment,
                hosts=hosts,
                exclude_hosts=exclude_hosts,
                ssh_credential_id=ssh_credential_id,
                ssh_credential_port=ssh_credential_port,
                smb_credential_id=smb_credential_id,
                esxi_credential_id=esxi_credential_id,
                snmp_credential_id=snmp_credential_id,
                alive_test=alive_test,
                allow_simultaneous_ips=allow_simultaneous_ips,
                reverse_lookup_only=reverse_lookup_only,
                reverse_lookup_unify=reverse_lookup_unify,
                port_list_id=port_list_id,
            )
        )

    def clone_target(self, target_id: EntityID) -> T:
        """Clone an existing target.

        Args:
            target_id: UUID of an existing target to clone.
        """
        return self._send_request_and_transform_response(
            Targets.clone_target(target_id)
        )

    def delete_target(
        self, target_id: EntityID, *, ultimate: bool | None = False
    ) -> T:
        """Delete an existing target.

        Args:
            target_id: UUID of an existing target to delete.
            ultimate: Whether to remove entirely or to the trashcan.
        """
        return self._send_request_and_transform_response(
            Targets.delete_target(target_id, ultimate=ultimate)
        )

    def get_target(
        self, target_id: EntityID, *, tasks: bool | None = None
    ) -> T:
        """Request a single target.

        Args:
            target_id: UUID of the target to request.
            tasks: Whether to include list of tasks that use the target
        """
        return self._send_request_and_transform_response(
            Targets.get_target(target_id, tasks=tasks)
        )

    def get_targets(
        self,
        *,
        filter_string: str | None = None,
        filter_id: EntityID | None = None,
        trash: bool | None = None,
        tasks: bool | None = None,
    ) -> T:
        """Request a list of targets.

        Args:
            filter_string: Filter term to use for the query.
            filter_id: UUID of an existing filter to use for the query.
            trash: Whether to include targets in the trashcan.
            tasks: Whether to include list of tasks that use the target.
        """
        return self._send_request_and_transform_response(
            Targets.get_targets(
                filter_string=filter_string,
                filter_id=filter_id,
                trash=trash,
                tasks=tasks,
            )
        )

    def get_scan_report(
        self,
        scan_report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
    ) -> T:
        """ "Request a structured summary of a single scan report.

        Args:
            scan_report_id: UUID of an existing scan report.
            filter_string: Filter term to apply to the report results.
            filter_id: UUID of a saved filter to apply to the report results.

        Returns:
            A request for the get_scan_report GMP command.

        Raises:
            RequiredArgument: If scan_report_id is not provided.
        """
        return self._send_request_and_transform_response(
            ScanReports.get_scan_report(
                scan_report_id=scan_report_id,
                filter_string=filter_string,
                filter_id=filter_id,
            )
        )

    def get_audit_report(  # type: ignore[override]
        self,
        audit_report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
    ) -> T:
        """Request a structured summary of a single audit report.

        Args:
            audit_report_id: UUID of an existing audit report.
            filter_string: Filter term to apply to the report results.
            filter_id: UUID of a saved filter to apply to the report results.

        Returns:
            A request for the get_audit_report GMP command.

        Raises:
            RequiredArgument: If audit_report_id is not provided.
        """
        return self._send_request_and_transform_response(
            AuditReport.get_audit_report(
                audit_report_id=audit_report_id,
                filter_string=filter_string,
                filter_id=filter_id,
            )
        )

    def get_audit_report_legacy(
        self,
        report_id: EntityID,
        *,
        filter_string: str | None = None,
        filter_id: str | None = None,
        delta_report_id: EntityID | None = None,
        report_format_id: str | ReportFormatType | None = None,
        ignore_pagination: bool | None = None,
        details: bool | None = True,
    ) -> T:
        """Request an audit report using the legacy command.

        Deprecated:
            Use ``get_audit_report`` instead. This method will be removed
            in the next major release.
        """
        return super().get_audit_report(
            report_id,
            filter_string=filter_string,
            filter_id=filter_id,
            delta_report_id=delta_report_id,
            report_format_id=report_format_id,
            ignore_pagination=ignore_pagination,
            details=details,
        )

    def export_scan_report(
        self,
        report_id: EntityID,
        format_id: EntityID,
        *,
        config_id: EntityID | None = None,
        filter_string: str | None = None,
        ignore_pagination: bool = False,
        lean: bool = False,
        notes_details: bool = False,
        overrides_details: bool = False,
        result_tags: bool = False,
    ) -> T:
        """Request an asynchronous export of a scan report.

        If an identical export is already pending or running, the existing
        report export is returned instead of creating a duplicate.

        Args:
            report_id: UUID of the scan report to export.
            format_id: UUID of the report format to apply.
            config_id: UUID of an optional report configuration.
            filter_string: Filter term to apply while generating the report.
            ignore_pagination: Whether pagination settings in the filter
                should be ignored.
            lean: Whether lean report data should be generated.
            notes_details: Whether note details should be included.
            overrides_details: Whether override details should be included.
            result_tags: Whether result tags should be included.

        Returns:
            A request for the export_scan_report GMP command.

        Raises:
            RequiredArgument: If report_id or format_id is not provided.
        """
        return self._send_request_and_transform_response(
            ScanReports.export_scan_report(
                report_id=report_id,
                format_id=format_id,
                config_id=config_id,
                filter_string=filter_string,
                ignore_pagination=ignore_pagination,
                lean=lean,
                notes_details=notes_details,
                overrides_details=overrides_details,
                result_tags=result_tags,
            )
        )
