"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

Shared pytest fixtures. `seeded_db_path` builds a real `mcp_store.db` with
hand-crafted (not model-computed) embedding vectors, so unit/integration
tests don't pay `sentence-transformers`' model-load cost — only
`tests/e2e` needs the real embedding model.
"""

from __future__ import annotations

import sqlite3
from pathlib import Path
from typing import AsyncIterator, Iterator

import aiosqlite
import pytest
import pytest_asyncio
import sqlite_vec

from {{ module_name }}.core.config import AuthMethod, Config
from {{ module_name }}.data.store import open_store


@pytest.fixture
def seeded_db_path(tmp_path: Path) -> Iterator[Path]:
    db_path = tmp_path / "mcp_store.db"
    conn = sqlite3.connect(db_path)
    conn.enable_load_extension(True)
    sqlite_vec.load(conn)
    conn.enable_load_extension(False)

    conn.execute(
        "CREATE TABLE endpoints ("
        "operation_id TEXT PRIMARY KEY, path TEXT NOT NULL, method TEXT NOT NULL, "
        "summary TEXT, description TEXT, input_schema TEXT NOT NULL, "
        "output_schema TEXT NOT NULL, auth_scheme_ref TEXT)"
    )
    conn.execute(
        "CREATE VIRTUAL TABLE semantic_endpoints USING vec0("
        "operation_id TEXT PRIMARY KEY, embedding FLOAT[4])"
    )
    conn.execute(
        "INSERT INTO endpoints VALUES "
        "('listWidgets', '/widgets', 'GET', 'List widgets', NULL, '{}', '[]', NULL)"
    )
    conn.execute(
        "INSERT INTO semantic_endpoints (operation_id, embedding) VALUES (?, ?)",
        ("listWidgets", sqlite_vec.serialize_float32([1.0, 0.0, 0.0, 0.0])),
    )
    conn.commit()
    conn.close()

    yield db_path


@pytest_asyncio.fixture
async def store_conn(seeded_db_path: Path) -> AsyncIterator[aiosqlite.Connection]:
    async with open_store(seeded_db_path) as conn:
        yield conn


@pytest.fixture
def sample_config() -> Config:
    return Config(
        url="https://api.example.com",
        auth_method=AuthMethod.{% if auth_methods | length > 0 %}{{ auth_methods.0.class_name | upper }}{% else %}NONE{% endif %},
    )
