namespace WebClientTpos.Server.AiChat;

/// <summary>
/// EN: Static registry of 12 MCP tool definitions for F&B operations.
///     These tools map to CatalogService, InventoryService, FnbEngine, and OrderService endpoints.
/// VI: Registry tinh cua 12 dinh nghia MCP tool cho hoat dong F&B.
///     Cac tool nay map den endpoint cua CatalogService, InventoryService, FnbEngine, va OrderService.
/// </summary>
public static class McpToolRegistry
{
    /// <summary>
    /// EN: Get all MCP tool definitions, injecting the given shopId as default for nullable shopId params.
    /// VI: Lay tat ca dinh nghia MCP tool, chen shopId da cho lam gia tri mac dinh cho tham so shopId nullable.
    /// </summary>
    public static List<AiToolDefinition> GetToolDefinitions(Guid shopId)
    {
        var shopIdDefault = shopId.ToString();

        return
        [
            // ═══════════════════════════════════════════════════════════════════
            // EN: Catalog tools
            // VI: Cac tool danh muc san pham
            // ═══════════════════════════════════════════════════════════════════
            new AiToolDefinition(
                "list_products",
                "EN: List products in a shop, optionally filtered by category and active status. " +
                "VI: Liet ke san pham trong cua hang, co the loc theo danh muc va trang thai hoat dong.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["categoryId"] = new { type = "string", description = "Filter by category ID (UUID)" },
                        ["isActive"] = new { type = "boolean", description = "Filter by active status" },
                        ["page"] = new { type = "integer", description = "Page number (default 1)" },
                        ["pageSize"] = new { type = "integer", description = "Items per page (default 20)" }
                    },
                    required = Array.Empty<string>()
                }),

            new AiToolDefinition(
                "create_product",
                "EN: Create a new product in a shop. " +
                "VI: Tao san pham moi trong cua hang.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["name"] = new { type = "string", description = "Product name" },
                        ["price"] = new { type = "number", description = "Product price" },
                        ["type"] = new { type = "string", description = "Product type (e.g. food, drink, service)" },
                        ["sku"] = new { type = "string", description = "Stock keeping unit code" },
                        ["description"] = new { type = "string", description = "Product description" },
                        ["categoryId"] = new { type = "string", description = "Category ID (UUID)" }
                    },
                    required = new[] { "shopId", "name", "price" }
                }),

            new AiToolDefinition(
                "update_product",
                "EN: Update an existing product's details. " +
                "VI: Cap nhat thong tin san pham hien co.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["productId"] = new { type = "string", description = "Product ID (UUID)" },
                        ["name"] = new { type = "string", description = "New product name" },
                        ["price"] = new { type = "number", description = "New product price" },
                        ["isActive"] = new { type = "boolean", description = "Active status" },
                        ["description"] = new { type = "string", description = "New description" }
                    },
                    required = new[] { "productId" }
                }),

            new AiToolDefinition(
                "delete_product",
                "EN: Delete (deactivate) a product. " +
                "VI: Xoa (vo hieu hoa) san pham.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["productId"] = new { type = "string", description = "Product ID (UUID)" }
                    },
                    required = new[] { "productId" }
                }),

            // ═══════════════════════════════════════════════════════════════════
            // EN: Inventory tools
            // VI: Cac tool quan ly kho
            // ═══════════════════════════════════════════════════════════════════
            new AiToolDefinition(
                "check_inventory",
                "EN: Check current inventory levels for a shop. " +
                "VI: Kiem tra muc ton kho hien tai cua cua hang.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["skip"] = new { type = "integer", description = "Number of items to skip" },
                        ["take"] = new { type = "integer", description = "Number of items to take" }
                    },
                    required = Array.Empty<string>()
                }),

            new AiToolDefinition(
                "record_intake",
                "EN: Record inventory stock-in (receiving goods). " +
                "VI: Ghi nhan nhap kho (nhan hang).",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["items"] = new
                        {
                            type = "array",
                            description = "List of items to stock in",
                            items = new
                            {
                                type = "object",
                                properties = new Dictionary<string, object>
                                {
                                    ["ingredientId"] = new { type = "string", description = "Ingredient ID (UUID)" },
                                    ["quantity"] = new { type = "number", description = "Quantity to add" },
                                    ["unitCost"] = new { type = "number", description = "Cost per unit" },
                                    ["note"] = new { type = "string", description = "Optional note" }
                                },
                                required = new[] { "ingredientId", "quantity" }
                            }
                        }
                    },
                    required = new[] { "shopId", "items" }
                }),

            new AiToolDefinition(
                "record_usage",
                "EN: Record inventory stock-out (usage/consumption). " +
                "VI: Ghi nhan xuat kho (su dung/tieu thu).",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["items"] = new
                        {
                            type = "array",
                            description = "List of items used",
                            items = new
                            {
                                type = "object",
                                properties = new Dictionary<string, object>
                                {
                                    ["ingredientId"] = new { type = "string", description = "Ingredient ID (UUID)" },
                                    ["quantity"] = new { type = "number", description = "Quantity used" },
                                    ["note"] = new { type = "string", description = "Optional note" }
                                },
                                required = new[] { "ingredientId", "quantity" }
                            }
                        }
                    },
                    required = new[] { "shopId", "items" }
                }),

            new AiToolDefinition(
                "low_stock_alerts",
                "EN: Get low stock alerts for ingredients below threshold. " +
                "VI: Lay canh bao ton kho thap cho nguyen lieu duoi nguong.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["threshold"] = new { type = "number", description = "Stock threshold (default defined by system)" }
                    },
                    required = Array.Empty<string>()
                }),

            // ═══════════════════════════════════════════════════════════════════
            // EN: FnB Engine tools
            // VI: Cac tool FnB Engine
            // ═══════════════════════════════════════════════════════════════════
            new AiToolDefinition(
                "list_recipes",
                "EN: List all recipes for a shop. " +
                "VI: Liet ke tat ca cong thuc cua cua hang.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault }
                    },
                    required = Array.Empty<string>()
                }),

            new AiToolDefinition(
                "create_recipe",
                "EN: Create a new recipe linking a product to its ingredients. " +
                "VI: Tao cong thuc moi lien ket san pham voi nguyen lieu.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["name"] = new { type = "string", description = "Recipe name" },
                        ["productId"] = new { type = "string", description = "Product ID (UUID)" },
                        ["ingredients"] = new
                        {
                            type = "array",
                            description = "List of recipe ingredients",
                            items = new
                            {
                                type = "object",
                                properties = new Dictionary<string, object>
                                {
                                    ["ingredientId"] = new { type = "string", description = "Ingredient ID (UUID)" },
                                    ["quantity"] = new { type = "number", description = "Quantity needed" },
                                    ["unit"] = new { type = "string", description = "Unit of measurement" }
                                },
                                required = new[] { "ingredientId", "quantity" }
                            }
                        }
                    },
                    required = new[] { "shopId", "name", "productId", "ingredients" }
                }),

            // ═══════════════════════════════════════════════════════════════════
            // EN: Analytics tools
            // VI: Cac tool phan tich
            // ═══════════════════════════════════════════════════════════════════
            new AiToolDefinition(
                "popular_items",
                "EN: Get popular/best-selling items for a given period. " +
                "VI: Lay san pham pho bien/ban chay nhat trong khoang thoi gian.",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault },
                        ["period"] = new
                        {
                            type = "string",
                            description = "Time period: today, 7d, or 30d",
                            @enum = new[] { "today", "7d", "30d" }
                        }
                    },
                    required = Array.Empty<string>()
                }),

            new AiToolDefinition(
                "cost_analysis",
                "EN: Get cost analysis report for a shop (ingredient costs, margins). " +
                "VI: Lay bao cao phan tich chi phi cho cua hang (chi phi nguyen lieu, bien loi nhuan).",
                new
                {
                    type = "object",
                    properties = new Dictionary<string, object>
                    {
                        ["shopId"] = new { type = "string", description = "Shop ID (UUID)", @default = shopIdDefault }
                    },
                    required = Array.Empty<string>()
                })
        ];
    }
}
