"""Skill topic: create-resource — unified quick-reference for all resource creation."""

from turumba_cli.skills.registry import SkillTopic, register_topics

topic = SkillTopic(
    name="create-resource",
    summary="Quick-reference: required params and one-shot examples for creating ANY resource",
    commands=[
        "turumba channels create",
        "turumba persons create",
        "turumba contacts create",
        "turumba templates create",
        "turumba group-messages create",
        "turumba scheduled-messages create",
        "turumba chat-endpoints create",
        "turumba conversation-configs create",
    ],
    notes=[
        "SETUP: Set default account_id once to avoid passing it every time:",
        "  turumba config set default_account_id <your-uuid>",
        "",
        "=== CHANNEL (no account_id needed — auto-injected by gateway) ===",
        "Required: --name, --type, --credentials",
        "Credential schemas by type:",
        '  telegram:  {"bot_token": "..."}',
        '  sms:       {"api_key": "...", "api_secret": "...", "sender_id": "..."}',
        '  whatsapp:  {"phone_number_id": "...", "access_token": "...", "business_account_id": "..."}',
        '  email:     {"smtp_host": "...", "smtp_port": 587, "username": "...", "password": "...", "from_address": "..."}',
        '  smpp:      {"host": "...", "port": 2775, "system_id": "...", "password": "..."}',
        '  messenger: {"page_access_token": "...", "page_id": "..."}',
        "",
        "=== PERSON (account_id REQUIRED) ===",
        "Required: --account-id (or config default)",
        "Optional: --properties (JSON), --group-id (repeatable)",
        "",
        "=== CONTACT (account_id REQUIRED) ===",
        "Required: --account-id (or config default)",
        "Optional: --properties (JSON)",
        "",
        "=== TEMPLATE (no account_id needed) ===",
        "Required: --name, --body",
        "Optional: --category, --channel-type, --language, --default-values, --fallback-strategy",
        "",
        "=== GROUP MESSAGE ===",
        "Required: (--body OR --template-id) + (--group-id OR --person-id OR --contact-id)",
        "Optional: --channel-id, --name, --exclude-person-id, --scheduled-at, --custom-values",
        "",
        "=== SCHEDULED MESSAGE ===",
        "Required: --send-type (single|group), --scheduled-at, (--body OR --template-id)",
        "  If single: --delivery-address required",
        "  If group: --group-id required",
        "  If --recurring: --recurrence-rule required",
        "Optional: --channel-id, --name, --timezone, --recurrence-end-at, --custom-values",
        "",
        "=== CHAT ENDPOINT (no account_id needed) ===",
        "Required: --name",
        "Optional: --channel-id, --welcome-message, --offline-message, --origin, "
        "--widget-config, --pre-chat-form, --description, --metadata",
        "",
        "=== CONVERSATION CONFIG (no account_id needed) ===",
        "Required: --name",
        "Optional: --priority, --audience-mode, --audience-group-ids, --source-channels, "
        "--creation-mode, --reopen-policy, --auto-resolve-hours, --default-team-id",
        "",
        "For detailed params, run: turumba skills show <resource-name>",
    ],
    examples=[
        # Channel
        'turumba channels create --name "My Bot" --type telegram '
        '--credentials \'{"bot_token": "123:ABC"}\'',
        # Person
        'turumba persons create --properties \'{"name": "Abebe", '
        '"phone": "+251911123456", "telegram_chat_id": "123456"}\'',
        # Contact
        'turumba contacts create --properties \'{"phone": "+251911...", '
        '"name": "Abebe", "email": "a@b.com"}\'',
        # Template
        'turumba templates create --name "welcome" '
        '--body "Hello {{name}}! Welcome to {{company}}."',
        # Group message
        "turumba group-messages create --group-id <gid> --channel-id <cid> "
        '--body "Hello everyone!"',
        # Scheduled single
        "turumba scheduled-messages create --send-type single "
        '--delivery-address "+251911..." --channel-id <cid> '
        '--body "Reminder" --scheduled-at 2026-04-01T09:00:00Z',
        # Scheduled group recurring
        "turumba scheduled-messages create --send-type group "
        "--group-id <gid> --channel-id <cid> "
        '--body "Weekly update" --scheduled-at 2026-04-07T09:00:00Z '
        "--recurring --recurrence-rule RRULE:FREQ=WEEKLY",
        # Chat endpoint
        'turumba chat-endpoints create --name "Support Chat" '
        '--welcome-message "How can we help?" --origin https://example.com',
        # Conversation config
        'turumba conversation-configs create --name "Default" --priority 0',
    ],
    workflows=[
        {
            "name": "Complete setup: channel + person + group message",
            "steps": [
                "turumba config set default_account_id <your-account-uuid>  # one-time setup",
                'turumba channels create --name "Telegram Bot" --type telegram '
                '--credentials \'{"bot_token": "..."}\'  # create channel',
                "turumba channels test-connection --id <channel-id>  # verify",
                'turumba persons create --properties \'{"name": "Abebe", '
                '"phone": "+251911..."}\' --group-id <gid>  # add recipient',
                "turumba group-messages create --group-id <gid> "
                '--channel-id <cid> --body "Hello!"  # send',
            ],
        },
        {
            "name": "Complete setup: template + scheduled recurring message",
            "steps": [
                'turumba templates create --name "weekly-report" '
                '--body "Hi {{name}}, here is your weekly report: {{content}}" -o json',
                "turumba scheduled-messages create --send-type group "
                "--group-id <gid> --template-id <tid> --channel-id <cid> "
                "--scheduled-at 2026-04-07T09:00:00Z "
                "--recurring --recurrence-rule RRULE:FREQ=WEEKLY "
                '--custom-values \'{"content": "This week summary..."}\'',
            ],
        },
    ],
    related=[
        "channels",
        "persons",
        "contacts",
        "templates",
        "group-messages",
        "scheduled-messages",
        "chat-endpoints",
        "conversation-configs",
    ],
)

register_topics(topic)
