"""Shared fixtures for Basecamp MCP tests."""

import pytest
import respx

from basecamp_mcp.client import BasecampClient


ACCOUNT_ID = 99999
BASE_URL = f"https://3.basecampapi.com/{ACCOUNT_ID}"

MOCK_CONFIG = {
    "account_id": ACCOUNT_ID,
    "access_token": "test-token",
    "refresh_token": "test-refresh",
    "client_id": "test-client-id",
    "client_secret": "test-client-secret",
}


def make_schedule_entry(
    id: int = 1,
    summary: str = "Team Standup",
    starts_at: str = "2026-03-20T09:00:00.000-05:00",
    ends_at: str = "2026-03-20T09:30:00.000-05:00",
    all_day: bool = False,
    description: str = "<p>Daily standup meeting</p>",
    participants: list | None = None,
    creator_name: str = "Jacob Filer",
    comments_count: int = 0,
    recurrence_schedule: dict | None = None,
    app_url: str = "",
) -> dict:
    entry = {
        "id": id,
        "type": "Schedule::Entry",
        "status": "active",
        "summary": summary,
        "starts_at": starts_at,
        "ends_at": ends_at,
        "all_day": all_day,
        "description": description,
        "creator": {"id": 42, "name": creator_name},
        "participants": participants or [],
        "comments_count": comments_count,
        "comments_url": f"{BASE_URL}/buckets/1/recordings/{id}/comments.json",
        "app_url": app_url
        or f"https://3.basecamp.com/{ACCOUNT_ID}/buckets/1/schedule_entries/{id}",
    }
    if recurrence_schedule:
        entry["recurrence_schedule"] = recurrence_schedule
    return entry


def make_project(
    project_id: int = 1, name: str = "Test Project", schedule_id: int = 100
) -> dict:
    return {
        "id": project_id,
        "name": name,
        "description": "",
        "purpose": "topic",
        "created_at": "2026-01-01T00:00:00.000Z",
        "updated_at": "2026-03-19T00:00:00.000Z",
        "app_url": f"https://3.basecamp.com/{ACCOUNT_ID}/projects/{project_id}",
        "dock": [
            {"id": 10, "name": "message_board", "enabled": True},
            {"id": 20, "name": "todoset", "enabled": True},
            {"id": 30, "name": "vault", "enabled": True},
            {"id": schedule_id, "name": "schedule", "enabled": True},
        ],
    }


@pytest.fixture
def client():
    return BasecampClient(MOCK_CONFIG)


@pytest.fixture
def mock_api():
    with respx.mock(base_url=BASE_URL) as api:
        yield api
