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


CONNECTOR = ConnectorDef(
    key="make_com",
    name="Make",
    category="automation",
    auth_type="api_key",
    version="01.01.00",
    icon="make",
    image_url=None,  # set to your CDN URL
    description="Trigger a Make scenario from your app via its Webhooks module. Use this to bridge P2HS Cloud capabilities (records, storage, AI, background jobs) into scenarios that Make's own operation limits and modules can't reach on their own.",
    docs_url="https://www.make.com/en/help/tools/webhooks",
    config_fields=("webhook_url", "workflow",),
    secret_fields=("webhook_secret",),
    config_field_defs=(
        ConnectorFieldDef(
            key="webhook_url",
            label="Scenario webhook URL",
            description="Webhook URL from the scenario trigger. Not called when you save.",
            placeholder="https://hook.us1.make.com/...",
            required=True,
            input_type="url",
        ),
        ConnectorFieldDef(
            key="workflow",
            label="Logical workflow name",
            description=(
                "Optional P2HS alias (e.g. lead-intake). Not a Make scenario ID. "
                "Required to bind this connection to automation.workflow.trigger."
            ),
            placeholder="lead-intake",
        ),
    ),
    secret_field_defs=(
        ConnectorFieldDef(
            key="webhook_secret",
            label="Webhook shared secret",
            description="Optional. Sent as X-P2HS-Webhook-Secret when the scenario is triggered.",
            input_type="password",
        ),
    ),
    actions=(
        ConnectorActionDef(
            key="trigger_scenario",
            slug="make_com.trigger_scenario",
            name="Trigger scenario",
            description="POST a JSON payload to the configured Make webhook to start that scenario.",
            input_schema={
                "type": "object",
                "properties": {"payload": {"type": "object"}},
                "required": ["payload"],
                "additionalProperties": False,
            },
            required_capabilities=("integrations.execute",),
            implements=("automation.workflow.trigger",),
        ),
    ),
    changelog=(
        ConnectorChangelogEntry(
            version="01.00.00",
            date="2026-09-06",
            notes="Initial release. Webhook-based scenario triggering, with optional API token for direct scenario management.",
        ),
        ConnectorChangelogEntry(
            version="01.01.00",
            date="2026-09-12",
            notes=(
                "Phase 1B: implements automation.workflow.trigger. "
                "Logical workflow alias is connection-side; webhook URL stays provider addressing."
            ),
        ),
    ),
)
