<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8">

<cfscript>
// Import Crimson Mediterranean Cookhouse menu
// This script creates the business, categories, and all items

response = { "OK": false, "steps": [], "errors": [] };

try {
    // Step 1: Create the business
    response.steps.append("Creating business record...");

    // Check if business already exists by name
    qCheck = queryTimed("
        SELECT ID FROM Businesses WHERE Name = :name
    ", { name: "Crimson Mediterranean Cookhouse" }, { datasource: "payfrit" });

    if (qCheck.recordCount > 0) {
        BusinessID = qCheck.BusinessID;
        response.steps.append("Business already exists with ID: " & BusinessID);
    } else {
        queryTimed("
            INSERT INTO Businesses (Name, BusinessOwnerUserID)
            VALUES (:name, :ownerID)
        ", {
            name: "Crimson Mediterranean Cookhouse",
            ownerID: 2  // UserID 2 (John)
        }, { datasource: "payfrit" });

        qNew = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
        BusinessID = qNew.id;
        response.steps.append("Created business with ID: " & BusinessID);
    }

    // Step 2: Create categories
    response.steps.append("Creating categories...");

    categories = [
        { id: "grill", name: "From the Grill", order: 1 },
        { id: "wraps", name: "Wraps", order: 2 },
        { id: "salads", name: "Salads", order: 3 },
        { id: "sides", name: "Sides", order: 4 },
        { id: "hot_coffee", name: "Hot Coffee", order: 5 },
        { id: "iced_coffee", name: "Iced Coffee", order: 6 },
        { id: "hot_tea", name: "Hot Teas", order: 7 },
        { id: "iced_tea", name: "Iced Teas", order: 8 },
        { id: "beverages", name: "Beverages", order: 9 }
    ];

    categoryMap = {}; // Maps category string ID to CategoryID

    for (cat in categories) {
        // Check if exists
        qCat = queryTimed("
            SELECT ID FROM Categories
            WHERE BusinessID = :bizID AND Name = :name
        ", { bizID: BusinessID, name: cat.name }, { datasource: "payfrit" });

        if (qCat.recordCount > 0) {
            categoryMap[cat.id] = qCat.CategoryID;
        } else {
            queryTimed("
                INSERT INTO Categories (BusinessID, Name, SortOrder)
                VALUES (:bizID, :name, :sortOrder)
            ", {
                bizID: BusinessID,
                name: cat.name,
                sortOrder: cat.order
            }, { datasource: "payfrit" });

            qNewCat = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
            categoryMap[cat.id] = qNewCat.id;
        }
    }

    response.steps.append("Categories created/found: " & structKeyList(categoryMap));

    // Step 3: Create modifier groups and their options
    response.steps.append("Creating modifier groups...");

    // We'll store modifier IDs for linking
    modifierMap = {}; // Maps modifier string ID to ItemID

    // Helper function to create a modifier group
    function createModifierGroup(categoryID, parentItemID, groupName, groupID, options, required, maxSelect) {
        // Check if group exists
        var qMod = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = :parentID
        ", { catID: categoryID, name: groupName, parentID: parentItemID }, { datasource: "payfrit" });

        var groupItemID = 0;
        if (qMod.recordCount > 0) {
            groupItemID = qMod.ItemID;
        } else {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, ParentItemID, Price, IsActive,
                    RequiresChildSelection, MaxNumSelectionReq, IsCollapsible, SortOrder)
                VALUES (:catID, :name, :parentID, 0, 1, :required, :maxSelect, 1, :sortOrder)
            ", {
                catID: categoryID,
                name: groupName,
                parentID: parentItemID,
                required: required ? 1 : 0,
                maxSelect: maxSelect,
                sortOrder: 100
            }, { datasource: "payfrit" });

            var qNewMod = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
            groupItemID = qNewMod.id;
        }

        // Create options
        var optionOrder = 1;
        for (var opt in options) {
            var qOpt = queryTimed("
                SELECT ID FROM Items
                WHERE CategoryID = :catID AND Name = :name AND ParentItemID = :parentID
            ", { catID: categoryID, name: opt.name, parentID: groupItemID }, { datasource: "payfrit" });

            if (qOpt.recordCount == 0) {
                var isDefault = (optionOrder == 1 && required) ? 1 : 0;
                queryTimed("
                    INSERT INTO Items (CategoryID, Name, ParentItemID, Price, IsActive,
                        IsCheckedByDefault, SortOrder)
                    VALUES (:catID, :name, :parentID, :price, 1, :isDefault, :sortOrder)
                ", {
                    catID: categoryID,
                    name: opt.name,
                    parentID: groupItemID,
                    price: opt.price_adjustment ?: 0,
                    isDefault: isDefault,
                    sortOrder: optionOrder
                }, { datasource: "payfrit" });
            }
            optionOrder++;
        }

        return groupItemID;
    }

    // Step 4: Create menu items
    response.steps.append("Creating menu items...");

    // === FROM THE GRILL ===
    grillCatID = categoryMap["grill"];
    grillItems = [
        { name: "Chicken Kabob (White Meat)", desc: "Served with rice & choice of sides", price: 22.00, hasSides: true },
        { name: "Chicken Kabob (Dark Meat)", desc: "Served with rice & choice of sides", price: 22.00, hasSides: true },
        { name: "Filet Mignon Kabob", desc: "Served with rice & choice of sides", price: 23.00, hasSides: true },
        { name: "Ground Sirloin Kabob", desc: "Two skewers of charbroiled seasoned ground sirloin with rice & choice of sides", price: 21.00, hasSides: true },
        { name: "Grilled Salmon", desc: "Served with rice & choice of sides", price: 23.00, hasSides: true },
        { name: "Falafel Veggie Plate", desc: "3 falafels drizzled with tahini, served with rice, choice of salad & sides", price: 20.00, hasSides: true },
        { name: "Chicken Shawarma Plate", desc: "Dark meat served with rice, lebanese turnips, tahini & choice of sides", price: 22.00, hasSides: true }
    ];

    itemOrder = 1;
    for (item in grillItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: grillCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, RequiresChildSelection, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :reqChild, :sortOrder)
            ", {
                catID: grillCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                reqChild: item.hasSides ? 1 : 0,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === WRAPS ===
    wrapsCatID = categoryMap["wraps"];
    wrapItems = [
        { name: "Chicken Wrap", desc: "White or dark meat wrapped with lettuce, cucumbers, tomatoes, hummus, garlic sauce & rose sauce", price: 19.50 },
        { name: "BBQ Chicken Wrap", desc: "White meat wrapped with lettuce, corn, black beans, tomatoes, scallions, tortilla strips, monterey jack cheese with herb ranch & bbq sauce", price: 19.50 },
        { name: "Filet Mignon Wrap", desc: "Wrapped with romaine lettuce, cucumbers, tomatoes, hummus, garlic sauce & rose sauce", price: 19.50 },
        { name: "Ground Sirloin Wrap", desc: "Wrapped with romaine lettuce, cucumbers, tomatoes, hummus, garlic sauce & rose sauce", price: 18.50 },
        { name: "Hummus Veggie Wrap", desc: "Wrapped with rice, lettuce, cucumbers, tomatoes, lebanese turnip, garlic sauce & rose sauce", price: 16.50 },
        { name: "Falafel Wrap", desc: "Wrapped with lettuce, cucumbers, tomatoes, lebanese turnips, tahini & garlic sauce", price: 17.50 },
        { name: "Spicy Falafel Wrap", desc: "Wrapped with lettuce, cucumbers, tomatoes, lebanese turnips, spicy tahini & garlic sauce", price: 17.50 },
        { name: "Sesame Falafel Wrap", desc: "Wrapped with romaine lettuce, broccoli, corn, red onions, cucumbers & rose sauce with sesame dressing", price: 17.50 },
        { name: "Crimson Chicken Wrap", desc: "White meat wrapped with lettuce, monterey jack cheese & tortilla strips with spicy herb ranch dressing", price: 19.50 },
        { name: "Kale Chicken Caesar Wrap", desc: "White meat with kale, romaine lettuce & shaved parmesan cheese with caesar dressing", price: 19.50 },
        { name: "Chicken Shawarma Wrap", desc: "Dark meat wrapped with lettuce, hummus, cucumbers, tomatoes, lebanese turnips, tahini & garlic sauce", price: 19.50 }
    ];

    itemOrder = 1;
    for (item in wrapItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: wrapsCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: wrapsCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === SALADS ===
    saladsCatID = categoryMap["salads"];
    saladItems = [
        { name: "Mediterranean Salad", desc: "Romaine lettuce, cucumbers, tomatoes, red onions, kalamata olives, garbanzo beans topped with feta cheese with balsamic vinaigrette", price: 19.50 },
        { name: "Cran-Ginger Salad", desc: "Mixed greens, tomatoes, broccoli, cucumbers, topped with strawberries, sliced almonds & dried cranberries in ginger dressing", price: 19.50 },
        { name: "Kale Salad", desc: "Red cabbage & carrots tossed in balsamic vinaigrette dressing", price: 19.50 },
        { name: "Asian Salad", desc: "Romaine lettuce, red cabbage, mandarin oranges, green onions, shredded carrots & asian noodles topped with sliced almonds in sesame dressing", price: 19.50 },
        { name: "BBQ Ranch Salad", desc: "Romaine lettuce, corn, black beans, tomatoes, scallions, fried onions & tortilla strips with monterey jack cheese in herb ranch & bbq sauce", price: 19.50 },
        { name: "Kale Caesar Salad", desc: "Kale, romaine lettuce & shaved parmesan cheese tossed in caesar dressing", price: 19.50 },
        { name: "Topolino Salad", desc: "Romaine lettuce, red onions, feta cheese, cranberries, sliced almonds & raisins in ranch vinaigrette dressing", price: 19.50 },
        { name: "Crimson Salad", desc: "Kale, romaine lettuce, avocado, corn, black beans, tomatoes, scallions, fried onions & tortilla strips with monterey jack cheese in spicy herb ranch", price: 19.50 }
    ];

    itemOrder = 1;
    for (item in saladItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: saladsCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: saladsCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === SIDES ===
    sidesCatID = categoryMap["sides"];
    sideItems = [
        { name: "Tomato Soup", desc: "Made fresh daily", price: 5.00 },
        { name: "Lentil Soup", desc: "Red lentils, onions, jalapeños & ginger", price: 5.00 },
        { name: "Tzatziki", desc: "Yogurt tossed with cucumbers & dried mint", price: 5.00 },
        { name: "Dolma", desc: "Grape leaves stuffed with rice & rose sauce", price: 5.00 },
        { name: "Kale Salad Side", desc: "Red cabbage & carrots in balsamic vinaigrette", price: 5.00 },
        { name: "Mini Greek Salad", desc: "Cucumbers, tomatoes, red onions & feta cheese with lemon vinaigrette", price: 5.00 },
        { name: "Mixed Green Salad", desc: "Cucumbers, tomatoes & shredded carrots with balsamic vinaigrette", price: 5.00 },
        { name: "Mini Broccoli Salad", desc: "Cucumbers, corn & red cabbage with sesame dressing", price: 5.00 },
        { name: "Shirazi Salad", desc: "Cucumbers, tomatoes, parsley with lemon vinaigrette", price: 5.00 },
        { name: "Babaganoush", desc: "Grilled eggplant, garlic, tahini, lemon juice, olive oil & sumac", price: 5.00 },
        { name: "Hummus", desc: "Chickpeas, garlic, lemon juice, & tahini topped with olive oil & paprika", price: 5.00 },
        { name: "Grilled Vegetables", desc: "Seasoned vegetables grilled to order", price: 5.00 },
        { name: "Sweet Potato Fries", desc: "Fried in non-GMO cooking oil", price: 5.00 },
        { name: "French Fries", desc: "Fried in non-GMO cooking oil", price: 5.00 }
    ];

    itemOrder = 1;
    for (item in sideItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: sidesCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: sidesCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === HOT COFFEE ===
    hotCoffeeCatID = categoryMap["hot_coffee"];
    hotCoffeeItems = [
        { name: "Coffee", desc: "Fresh brewed Intelligentsia coffee", price: 4.00 },
        { name: "Espresso", desc: "Single shot espresso", price: 3.50 },
        { name: "Americano", desc: "Espresso with hot water", price: 4.50 },
        { name: "Cappuccino", desc: "Espresso with steamed milk and foam", price: 5.00 },
        { name: "Latte", desc: "Espresso with steamed milk", price: 5.25 },
        { name: "Macchiato", desc: "Espresso marked with foam", price: 4.50 },
        { name: "Vanilla Latte", desc: "Espresso with steamed milk and vanilla", price: 5.50 },
        { name: "Caramel Latte", desc: "Espresso with steamed milk and caramel", price: 5.50 },
        { name: "Hazelnut Latte", desc: "Espresso with steamed milk and hazelnut", price: 5.50 },
        { name: "Honey Vanilla Latte", desc: "Espresso with steamed milk, honey and vanilla", price: 5.75 },
        { name: "Mocha Latte", desc: "Espresso with steamed milk and chocolate", price: 5.50 },
        { name: "Mocha Mint", desc: "Espresso with steamed milk, chocolate and mint", price: 5.75 },
        { name: "Hot Chocolate", desc: "Rich hot chocolate", price: 4.50 }
    ];

    itemOrder = 1;
    for (item in hotCoffeeItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: hotCoffeeCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: hotCoffeeCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === ICED COFFEE ===
    icedCoffeeCatID = categoryMap["iced_coffee"];
    icedCoffeeItems = [
        { name: "Iced Coffee", desc: "Cold brewed Intelligentsia coffee over ice", price: 4.25 },
        { name: "Iced Espresso", desc: "Espresso over ice", price: 3.50 },
        { name: "Iced Americano", desc: "Espresso with cold water over ice", price: 4.75 },
        { name: "Iced Latte", desc: "Espresso with cold milk over ice", price: 5.25 },
        { name: "Iced Vanilla Latte", desc: "Espresso with cold milk and vanilla over ice", price: 5.75 },
        { name: "Iced Caramel Macchiato", desc: "Espresso with cold milk and caramel over ice", price: 5.75 },
        { name: "Iced Honey Vanilla Latte", desc: "Espresso with cold milk, honey and vanilla over ice", price: 6.00 },
        { name: "Iced Mocha", desc: "Espresso with cold milk and chocolate over ice", price: 5.75 },
        { name: "Iced Mocha Mint", desc: "Espresso with cold milk, chocolate and mint over ice", price: 6.00 },
        { name: "Angeleno", desc: "House specialty iced coffee drink", price: 6.00 }
    ];

    itemOrder = 1;
    for (item in icedCoffeeItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: icedCoffeeCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: icedCoffeeCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === HOT TEAS ===
    hotTeaCatID = categoryMap["hot_tea"];
    hotTeaItems = [
        { name: "Organic Chamomile", desc: "Soothing organic chamomile tea", price: 4.00 },
        { name: "Organic Earl Grey", desc: "Classic bergamot-infused black tea", price: 4.00 },
        { name: "Organic Hot Chai Tea", desc: "Spiced organic chai tea", price: 4.00 },
        { name: "Organic House Chai Tea Latte", desc: "Spiced chai with steamed milk", price: 5.00 },
        { name: "Organic Jasmine Green", desc: "Delicate jasmine-scented green tea", price: 4.00 },
        { name: "Organic Mint Melange", desc: "Refreshing mint tea blend", price: 4.00 },
        { name: "Matcha Green Tea Latte", desc: "Japanese matcha with steamed milk", price: 5.75 },
        { name: "Persian Latte", desc: "Traditional Persian-style tea latte", price: 5.50 }
    ];

    itemOrder = 1;
    for (item in hotTeaItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: hotTeaCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: hotTeaCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === ICED TEAS ===
    icedTeaCatID = categoryMap["iced_tea"];
    icedTeaItems = [
        { name: "Organic Black Iced Tea", desc: "Fresh brewed organic black tea over ice", price: 4.00 },
        { name: "Organic Tropical Green Iced Tea", desc: "Tropical-infused green tea over ice", price: 4.00 },
        { name: "Organic Hibiscus Berry Iced Tea", desc: "Hibiscus and berry tea blend over ice", price: 4.00 },
        { name: "Organic Hibiscus Berry Tea Palmer", desc: "Hibiscus berry tea with lemonade", price: 4.00 },
        { name: "Organic Black Tea Palmer", desc: "Black tea with lemonade", price: 4.00 },
        { name: "Organic Tropical Green Tea Palmer", desc: "Tropical green tea with lemonade", price: 4.00 },
        { name: "Iced Organic House Chai Tea Latte", desc: "Spiced chai with cold milk over ice", price: 5.25 },
        { name: "Iced Persian Latte", desc: "Persian-style tea latte over ice", price: 5.75 },
        { name: "Iced Matcha Green Tea Latte", desc: "Japanese matcha with cold milk over ice", price: 6.00 }
    ];

    itemOrder = 1;
    for (item in icedTeaItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: icedTeaCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: icedTeaCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // === BEVERAGES ===
    bevCatID = categoryMap["beverages"];
    bevItems = [
        { name: "Coke", desc: "Coca-Cola", price: 3.00 },
        { name: "Diet Coke", desc: "Diet Coca-Cola", price: 3.00 },
        { name: "Sprite", desc: "Lemon-lime soda", price: 3.00 },
        { name: "Sparkling Water", desc: "Carbonated mineral water", price: 3.00 },
        { name: "Orange Pellegrino", desc: "San Pellegrino Aranciata", price: 2.50 },
        { name: "Bottled Water", desc: "Still bottled water", price: 3.00 },
        { name: "Lemonade", desc: "Fresh lemonade", price: 3.00 },
        { name: "Strawberry Lemonade", desc: "Fresh lemonade with strawberry", price: 3.00 },
        { name: "Milk", desc: "Cold milk", price: 3.00 },
        { name: "Orange Juice", desc: "Fresh orange juice", price: 3.50 }
    ];

    itemOrder = 1;
    for (item in bevItems) {
        qItem = queryTimed("
            SELECT ID FROM Items
            WHERE CategoryID = :catID AND Name = :name AND ParentItemID = 0
        ", { catID: bevCatID, name: item.name }, { datasource: "payfrit" });

        if (qItem.recordCount == 0) {
            queryTimed("
                INSERT INTO Items (CategoryID, Name, Description, ParentItemID, Price,
                    IsActive, SortOrder)
                VALUES (:catID, :name, :desc, 0, :price, 1, :sortOrder)
            ", {
                catID: bevCatID,
                name: item.name,
                desc: item.desc,
                price: item.price,
                sortOrder: itemOrder
            }, { datasource: "payfrit" });
        }
        itemOrder++;
    }

    // Count total items
    qCount = queryTimed("
        SELECT COUNT(*) as cnt FROM Items i
        INNER JOIN Categories c ON c.ID = i.CategoryID
        WHERE c.BusinessID = :bizID
    ", { bizID: BusinessID }, { datasource: "payfrit" });

    response.OK = true;
    response.BusinessID = BusinessID;
    response.totalItems = qCount.cnt;
    response.steps.append("Import complete! BusinessID: " & BusinessID & ", Total items: " & qCount.cnt);

} catch (any e) {
    response.errors.append(e.message);
    response.errors.append(e.detail);
}

writeOutput(serializeJSON(response));
</cfscript>
