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


CONNECTOR = ConnectorDef(
    key="google_calendar",
    name="Google Calendar",
    category="scheduling",
    auth_type="oauth",
    version="01.00.00",
    icon="google_calendar",
    image_url=None,  # set to your CDN URL
    description="Create, update, delete, and free/busy-query Google Calendar events.",
    docs_url="https://developers.google.com/calendar/api/v3/reference",
    config_fields=("calendar_id",),
    secret_fields=("access_token", "refresh_token", "client_id", "client_secret",),
    config_field_defs=(
        ConnectorFieldDef(
            key="calendar_id",
            label="Calendar ID",
            description="Defaults to primary when omitted on actions.",
            placeholder="primary",
        ),
    ),
    secret_field_defs=(
        ConnectorFieldDef(key="access_token", label="Access token", required=True, input_type="password"),
        ConnectorFieldDef(key="refresh_token", label="Refresh token", required=True, input_type="password"),
        ConnectorFieldDef(key="client_id", label="OAuth client ID", required=True),
        ConnectorFieldDef(key="client_secret", label="OAuth client secret", required=True, input_type="password"),
    ),
    actions=(
        ConnectorActionDef(
            key="create_event",
            slug="google_calendar.create_event",
            name="Create event",
            description="Create a Google Calendar event.",
            input_schema={
                "type": "object",
                "properties": {
                    "calendar_id": {"type": "string"},
                    "summary": {"type": "string"},
                    "description": {"type": "string"},
                    "start": {"type": "string"},
                    "end": {"type": "string"},
                    "timezone": {"type": "string"},
                    "attendees": {"type": "array"},
                    "location": {"type": "string"},
                },
                "required": ["summary", "start", "end"],
                "additionalProperties": True,
            },
            required_scopes=("https://www.googleapis.com/auth/calendar.events",),
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="update_event",
            slug="google_calendar.update_event",
            name="Update event",
            description="Patch an existing Google Calendar event.",
            input_schema={
                "type": "object",
                "properties": {
                    "calendar_id": {"type": "string"},
                    "event_id": {"type": "string"},
                    "summary": {"type": "string"},
                    "description": {"type": "string"},
                    "start": {"type": "string"},
                    "end": {"type": "string"},
                    "timezone": {"type": "string"},
                    "attendees": {"type": "array"},
                    "location": {"type": "string"},
                },
                "required": ["event_id"],
                "additionalProperties": True,
            },
            required_scopes=("https://www.googleapis.com/auth/calendar.events",),
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="delete_event",
            slug="google_calendar.delete_event",
            name="Delete event",
            description="Delete a Google Calendar event.",
            input_schema={
                "type": "object",
                "properties": {"calendar_id": {"type": "string"}, "event_id": {"type": "string"}},
                "required": ["event_id"],
                "additionalProperties": False,
            },
            required_scopes=("https://www.googleapis.com/auth/calendar.events",),
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="get_event",
            slug="google_calendar.get_event",
            name="Get event",
            description="Retrieve a Google Calendar event.",
            input_schema={
                "type": "object",
                "properties": {"calendar_id": {"type": "string"}, "event_id": {"type": "string"}},
                "required": ["event_id"],
                "additionalProperties": False,
            },
            required_scopes=("https://www.googleapis.com/auth/calendar.events",),
            required_capabilities=("integrations.execute",),
        ),
        ConnectorActionDef(
            key="query_freebusy",
            slug="google_calendar.query_freebusy",
            name="Query free/busy",
            description="Query free/busy intervals for one or more calendars.",
            input_schema={
                "type": "object",
                "properties": {
                    "calendar_ids": {"type": "array"},
                    "time_min": {"type": "string"},
                    "time_max": {"type": "string"},
                },
                "required": ["time_min", "time_max"],
                "additionalProperties": False,
            },
            required_scopes=("https://www.googleapis.com/auth/calendar.readonly",),
            required_capabilities=("integrations.execute",),
        ),
    ),
    triggers=(
        ConnectorTriggerDef(
            key="event_created",
            event_type="google_calendar.event.created",
            name="Calendar event created",
        ),
        ConnectorTriggerDef(
            key="event_updated",
            event_type="google_calendar.event.updated",
            name="Calendar event updated",
        ),
        ConnectorTriggerDef(
            key="event_deleted",
            event_type="google_calendar.event.deleted",
            name="Calendar event deleted",
        ),
    ),
)
