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


CONNECTOR = ConnectorDef(
    key="linkedin",
    name="LinkedIn",
    category="publishing",
    auth_type="oauth",
    version="01.00.00",
    icon="linkedin",
    description="Publish organic text, image, video, document, or article posts to an authorized LinkedIn organization or member.",
    docs_url="https://learn.microsoft.com/en-us/linkedin/marketing/community-management/shares/posts-api",
    config_fields=("organization_urn", "linkedin_version"),
    secret_fields=("access_token",),
    config_field_defs=(
        ConnectorFieldDef(
            key="organization_urn",
            label="Organization URN",
            description="Optional default author, such as urn:li:organization:12345. It must be authorized for the connected token.",
        ),
        ConnectorFieldDef(
            key="linkedin_version",
            label="LinkedIn API version",
            description="Optional YYYYMM version header. Defaults to the current monthly version; update during LinkedIn migrations.",
            default="202609",
        ),
    ),
    secret_field_defs=(
        ConnectorFieldDef(
            key="access_token",
            label="OAuth access token",
            description="OAuth token with the w_member_social permission for the selected author.",
            required=True,
            input_type="password",
        ),
    ),
    actions=(
        ConnectorActionDef(
            key="create_post",
            slug="linkedin.create_post",
            name="Create organic post",
            description="Create a versioned LinkedIn organic post. Media content must reference an already-uploaded LinkedIn asset URN.",
            input_schema={
                "type": "object",
                "properties": {
                    "author": {"type": "string"},
                    "commentary": {"type": "string"},
                    "visibility": {"enum": ["PUBLIC", "CONNECTIONS"]},
                    "lifecycle_state": {"enum": ["PUBLISHED", "DRAFT"]},
                    "distribution": {"type": "object"},
                    "content": {"type": "object"},
                    "is_reshare_disabled_by_author": {"type": "boolean"},
                },
                "required": ["commentary"],
                "additionalProperties": False,
            },
            required_scopes=("w_member_social",),
            required_capabilities=("integrations.execute",),
        ),
    ),
    changelog=(
        ConnectorChangelogEntry(
            version="01.00.00",
            date="2026-09-20",
            notes="Initial organic Posts API adapter using LinkedIn's 202609 versioned REST contract.",
        ),
    ),
)
