"""Auto-generated MCP server.

Generated by auto-mcp.
"""

from typing import Any
from mcp.server.fastmcp import FastMCP

import sqlite_tools

# Create MCP server
mcp = FastMCP(name="sqlite-tools")

# Tools

@mcp.tool(name="aggregate_query")
def aggregate_query(table_name: str, column: str, function: str = 'SUM', group_by: str | None = None, connection: str = 'default'):
    """Run an aggregate query on a table."""
    return sqlite_tools.aggregate_query(table_name=table_name, column=column, function=function, group_by=group_by, connection=connection)


@mcp.tool(name="connect_database")
def connect_database(database: str = ':memory:', name: str = 'default'):
    """Connect to a SQLite database."""
    return sqlite_tools.connect_database(database=database, name=name)


@mcp.tool(name="count_rows")
def count_rows(table_name: str, conditions: dict[str, Any] | None = None, connection: str = 'default'):
    """Count rows in a table."""
    return sqlite_tools.count_rows(table_name=table_name, conditions=conditions, connection=connection)


@mcp.tool(name="create_sample_data")
def create_sample_data(connection: str = 'default'):
    """Create sample tables with test data."""
    return sqlite_tools.create_sample_data(connection=connection)


@mcp.tool(name="create_table")
def create_table(table_name: str, columns: dict, connection: str = 'default'):
    """Create a new table."""
    return sqlite_tools.create_table(table_name=table_name, columns=columns, connection=connection)


@mcp.tool(name="delete_rows")
def delete_rows(table_name: str, conditions: dict, connection: str = 'default'):
    """Delete rows matching conditions."""
    return sqlite_tools.delete_rows(table_name=table_name, conditions=conditions, connection=connection)


@mcp.tool(name="describe_table")
def describe_table(table_name: str, connection: str = 'default'):
    """Get the schema of a table."""
    return sqlite_tools.describe_table(table_name=table_name, connection=connection)


@mcp.tool(name="disconnect_database")
def disconnect_database(name: str = 'default'):
    """Close a database connection."""
    return sqlite_tools.disconnect_database(name=name)


@mcp.tool(name="drop_table")
def drop_table(table_name: str, connection: str = 'default'):
    """Drop a table."""
    return sqlite_tools.drop_table(table_name=table_name, connection=connection)


@mcp.tool(name="execute_query")
def execute_query(sql: str, parameters: list[Any] | None = None, connection: str = 'default'):
    """Execute a SQL query and return results."""
    return sqlite_tools.execute_query(sql=sql, parameters=parameters, connection=connection)


@mcp.tool(name="execute_script")
def execute_script(sql_script: str, connection: str = 'default'):
    """Execute a SQL script with multiple statements."""
    return sqlite_tools.execute_script(sql_script=sql_script, connection=connection)


@mcp.tool(name="get_database_info")
def get_database_info(connection: str = 'default'):
    """Get information about the database."""
    return sqlite_tools.get_database_info(connection=connection)


@mcp.tool(name="insert_many")
def insert_many(table_name: str, rows: list, connection: str = 'default'):
    """Insert multiple rows into a table."""
    return sqlite_tools.insert_many(table_name=table_name, rows=rows, connection=connection)


@mcp.tool(name="insert_row")
def insert_row(table_name: str, data: dict, connection: str = 'default'):
    """Insert a row into a table."""
    return sqlite_tools.insert_row(table_name=table_name, data=data, connection=connection)


@mcp.tool(name="join_query")
def join_query(table1: str, table2: str, join_column1: str, join_column2: str, select_columns: list[str] | None = None, join_type: str = 'INNER', connection: str = 'default'):
    """Execute a JOIN query between two tables."""
    return sqlite_tools.join_query(table1=table1, table2=table2, join_column1=join_column1, join_column2=join_column2, select_columns=select_columns, join_type=join_type, connection=connection)


@mcp.tool(name="list_tables")
def list_tables(connection: str = 'default'):
    """List all tables in the database."""
    return sqlite_tools.list_tables(connection=connection)


@mcp.tool(name="select_all")
def select_all(table_name: str, limit: int | None = None, offset: int = 0, connection: str = 'default'):
    """Select all rows from a table."""
    return sqlite_tools.select_all(table_name=table_name, limit=limit, offset=offset, connection=connection)


@mcp.tool(name="select_where")
def select_where(table_name: str, conditions: dict, connection: str = 'default'):
    """Select rows matching conditions."""
    return sqlite_tools.select_where(table_name=table_name, conditions=conditions, connection=connection)


@mcp.tool(name="update_rows")
def update_rows(table_name: str, data: dict, conditions: dict, connection: str = 'default'):
    """Update rows matching conditions."""
    return sqlite_tools.update_rows(table_name=table_name, data=data, conditions=conditions, connection=connection)




if __name__ == "__main__":
    mcp.run()
