import logging
import sys

from bria_client.clients.settings import BriaSettings
from mcp.server.fastmcp import FastMCP
from mcp.types import ToolAnnotations

from bria_mcp.tools.editing import (
    blur_background,
    crop_out_foreground,
    enhance_image,
    erase_foreground,
    expand_image,
    generate_background,
    increase_resolution,
    remove_background,
)
from bria_mcp.tools.fibo import generate_image
from bria_mcp.tools.video import erase_from_video, increase_video_resolution, remove_video_background, video_mask_by_prompt

logger = logging.getLogger(__name__)
mcp = FastMCP("BriaMCP")

BriaApiToolAnnotations = ToolAnnotations(readOnlyHint=True, idempotentHint=True, openWorldHint=True)

mcp.add_tool(remove_background, annotations=BriaApiToolAnnotations)
mcp.add_tool(blur_background, annotations=BriaApiToolAnnotations)
mcp.add_tool(crop_out_foreground, annotations=BriaApiToolAnnotations)
mcp.add_tool(increase_resolution, annotations=BriaApiToolAnnotations)
mcp.add_tool(expand_image, annotations=BriaApiToolAnnotations)
mcp.add_tool(generate_background, annotations=BriaApiToolAnnotations)
mcp.add_tool(erase_foreground, annotations=BriaApiToolAnnotations)
mcp.add_tool(enhance_image, annotations=BriaApiToolAnnotations)

mcp.add_tool(generate_image, annotations=BriaApiToolAnnotations)


mcp.add_tool(remove_video_background, annotations=BriaApiToolAnnotations)
mcp.add_tool(increase_video_resolution, annotations=BriaApiToolAnnotations)
mcp.add_tool(video_mask_by_prompt, annotations=BriaApiToolAnnotations)
mcp.add_tool(erase_from_video, annotations=BriaApiToolAnnotations)


def main():
    transport = sys.argv[1] if len(sys.argv) > 1 else "stdio"  # type: ignore
    if transport == "stdio":
        assert BriaSettings().api_token is not None, "api_token is required for stdio transport"
    logger.info(f"Starting server in {transport} mode")
    mcp.run(transport=transport)  # type: ignore
