"""Gmail tool configuration."""

from __future__ import annotations

from typing import TYPE_CHECKING

from mindroom.tool_system.declarations import (
    ConfigField,
    SetupType,
    ToolCategory,
    ToolManagedInitArg,
    ToolStatus,
)
from mindroom.tool_system.registration import register_tool_with_metadata

if TYPE_CHECKING:
    from mindroom.custom_tools.gmail import GmailTools


@register_tool_with_metadata(
    name="gmail",
    display_name="Gmail",
    description="Read, search, and manage Gmail emails",
    category=ToolCategory.EMAIL,
    status=ToolStatus.REQUIRES_CONFIG,
    setup_type=SetupType.OAUTH,
    auth_provider="google_gmail",
    icon="SiGmail",
    icon_color="text-red-500",
    config_fields=[
        ConfigField(
            name="get_latest_emails",
            label="Get Latest Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow retrieving the latest emails",
        ),
        ConfigField(
            name="get_emails_from_user",
            label="Get Emails From User",
            type="boolean",
            required=False,
            default=True,
            description="Allow retrieving emails from specific users",
        ),
        ConfigField(
            name="get_unread_emails",
            label="Get Unread Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow retrieving unread emails",
        ),
        ConfigField(
            name="get_starred_emails",
            label="Get Starred Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow retrieving starred emails",
        ),
        ConfigField(
            name="search_emails",
            label="Search Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow searching through emails",
        ),
        ConfigField(
            name="create_draft_email",
            label="Create Draft Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow creating draft emails",
        ),
        ConfigField(
            name="send_email",
            label="Send Emails",
            type="boolean",
            required=False,
            default=True,
            description="Allow sending emails",
        ),
        ConfigField(
            name="send_email_reply",
            label="Send Email Replies",
            type="boolean",
            required=False,
            default=True,
            description="Allow sending replies to emails",
        ),
    ],
    managed_init_args=(
        ToolManagedInitArg.RUNTIME_PATHS,
        ToolManagedInitArg.CREDENTIALS_MANAGER,
        ToolManagedInitArg.WORKER_TARGET,
    ),
    dependencies=["google-api-python-client", "google-auth", "google-auth-oauthlib", "google-auth-httplib2"],
    docs_url="https://docs.agno.com/tools/toolkits/social/gmail",
    function_names=(
        "apply_label",
        "archive_email",
        "create_draft_email",
        "delete_custom_label",
        "download_attachment",
        "get_draft",
        "get_emails_by_context",
        "get_emails_by_date",
        "get_emails_by_thread",
        "get_emails_from_user",
        "get_latest_emails",
        "get_message",
        "get_starred_emails",
        "get_thread",
        "get_unread_emails",
        "list_custom_labels",
        "list_drafts",
        "list_labels",
        "mark_email_as_read",
        "mark_email_as_unread",
        "modify_message_labels",
        "modify_thread_labels",
        "remove_label",
        "search_emails",
        "search_threads",
        "send_draft",
        "send_email",
        "send_email_reply",
        "star_email",
        "trash_message",
        "trash_thread",
        "unstar_email",
        "update_draft",
    ),
)
def gmail_tools() -> type[GmailTools]:
    """Return Gmail tools for email management."""
    from mindroom.custom_tools.gmail import GmailTools

    return GmailTools
