import os
from dotenv import load_dotenv
from mcp.server.fastmcp import FastMCP

from iot_mcp_server import util

# Load environment variables
load_dotenv()

# Create an MCP server
mcp = FastMCP("IoT MCP Server")

@mcp.tool()
def list_products() -> str:
    """List products"""
    products = util.list_products()
    return products

@mcp.tool()
def get_product_definition(product_key: str) -> str:
    """Get product TSL definition by productKey"""
    tsl_json = util.get_product_tsl_json(product_key)
    return tsl_json

@mcp.tool()
def list_devices(product_key: str) -> str:
    """List devices in product which is specified by productKey"""
    devices = util.list_devices(product_key)
    return devices

@mcp.tool()
def power_switch(product_key: str, device_key: str, on_off: str) -> str:
    """Turn the device power switch on or off, the device is specified by productKey and deviceKey"""
    devices = util.power_switch(product_key, device_key, on_off)
    return devices

@mcp.tool()
def greet(name: str) -> str:
    """Greet a person by name"""
    return f"It is an awesome world, isn't it? {name}"