from src.domain.connectors.catalog._base import (
    ConnectorActionDef,
    ConnectorChangelogEntry,
    ConnectorDef,
    ConnectorFieldDef,
)


CONNECTOR = ConnectorDef(
    key="resend",
    name="Resend",
    category="email",
    auth_type="api_key",
    version="01.01.00",
    icon="resend",
    image_url=None,  # set to your CDN URL
    description="Transactional email delivery, scheduled emails, batch sends, and email lifecycle operations.",
    docs_url="https://resend.com/docs/api-reference/emails/send-email",
    config_fields=("from_email", "from_name",),
    secret_fields=("api_key",),
    config_field_defs=(
        ConnectorFieldDef(
            key="from_email",
            label="From email",
            description="A sending address verified in your Resend account.",
            placeholder="noreply@yourdomain.com",
            required=True,
        ),
        ConnectorFieldDef(
            key="from_name",
            label="From name",
            description="Display name shown to recipients.",
            placeholder="Acme Inc.",
        ),
    ),
    secret_field_defs=(
        ConnectorFieldDef(
            key="api_key",
            label="API key",
            description="Resend API key with sending permission.",
            placeholder="re_...",
            required=True,
            input_type="password",
        ),
    ),
    actions=(
        ConnectorActionDef(
            key="send_email",
            slug="resend.send_email",
            name="Send email",
            description="Send a transactional email immediately or later with scheduled_at.",
            input_schema={
                "type": "object",
                "properties": {
                    "to": {"type": ["string", "array"]},
                    "subject": {"type": "string"},
                    "html": {"type": "string"},
                    "text": {"type": "string"},
                    "from": {"type": "string"},
                    "reply_to": {"type": ["string", "array"]},
                    "scheduled_at": {"type": "string"},
                    "cc": {"type": "array"},
                    "bcc": {"type": "array"},
                    "headers": {"type": "object"},
                    "tags": {"type": "array"},
                    "attachments": {"type": "array"},
                    "topic_id": {"type": "string"},
                    "template": {"type": "object"},
                },
                "required": ["to", "subject"],
                "additionalProperties": True,
            },
            required_capabilities=("integrations.execute",),
            implements=("email.send",),
        ),
        ConnectorActionDef(
            key="send_batch_emails",
            slug="resend.send_batch_emails",
            name="Send batch emails",
            description="Send up to 100 transactional emails in one Resend API call. Resend does not support attachments or scheduled_at on batch sends.",
            input_schema={
                "type": "object",
                "properties": {"emails": {"type": "array"}},
                "required": ["emails"],
                "additionalProperties": False,
            },
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="retrieve_email",
            slug="resend.retrieve_email",
            name="Retrieve email",
            description="Retrieve a single email by Resend email id.",
            input_schema={
                "type": "object",
                "properties": {"email_id": {"type": "string"}},
                "required": ["email_id"],
                "additionalProperties": False,
            },
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="update_email",
            slug="resend.update_email",
            name="Update scheduled email",
            description="Patch a scheduled email, currently used to update scheduled_at.",
            input_schema={
                "type": "object",
                "properties": {"email_id": {"type": "string"}, "scheduled_at": {"type": "string"}},
                "required": ["email_id", "scheduled_at"],
                "additionalProperties": False,
            },
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="cancel_email",
            slug="resend.cancel_email",
            name="Cancel scheduled email",
            description="Cancel a scheduled email.",
            input_schema={
                "type": "object",
                "properties": {"email_id": {"type": "string"}},
                "required": ["email_id"],
                "additionalProperties": False,
            },
            required_capabilities=("integrations.execute",),
        ),
    ),
    changelog=(
        ConnectorChangelogEntry(
            version="01.00.00",
            date="2026-04-26",
            notes="Initial release. Actions: send_email.",
        ),
        ConnectorChangelogEntry(
            version="01.01.00",
            date="2026-04-26",
            notes="Added scheduled_at support, batch send, retrieve email, update scheduled email, and cancel scheduled email.",
        ),
    ),
)
