"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.orchestrateInterfaceGroups = orchestrateInterfaceGroups;
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
const typia_1 = __importDefault(require("typia"));
const uuid_1 = require("uuid");
const assertSchemaModel_1 = require("../../context/assertSchemaModel");
const transformInterfaceGroupHistories_1 = require("./histories/transformInterfaceGroupHistories");
function orchestrateInterfaceGroups(ctx, props) {
    return __awaiter(this, void 0, void 0, function* () {
        var _a, _b, _c;
        const start = new Date();
        const pointer = {
            value: null,
        };
        const { tokenUsage } = yield ctx.conversate({
            source: "interfaceGroups",
            histories: (0, transformInterfaceGroupHistories_1.transformInterfaceGroupHistories)({
                state: ctx.state(),
                instruction: props.instruction,
            }),
            controller: createController({
                model: ctx.model,
                build: (next) => {
                    pointer.value = next;
                },
            }),
            enforceFunctionCall: true,
            message: (_a = props.message) !== null && _a !== void 0 ? _a : "Design API operations for the given assets.",
        });
        if (pointer.value === null)
            throw new Error("Failed to generate groups."); // unreachable
        return {
            type: "interfaceGroups",
            id: (0, uuid_1.v7)(),
            created_at: start.toISOString(),
            groups: pointer.value.groups,
            tokenUsage,
            step: (_c = (_b = ctx.state().analyze) === null || _b === void 0 ? void 0 : _b.step) !== null && _c !== void 0 ? _c : 0,
        };
    });
}
function createController(props) {
    (0, assertSchemaModel_1.assertSchemaModel)(props.model);
    const application = collection[props.model];
    return {
        protocol: "class",
        name: "interface",
        application,
        execute: {
            makeGroups: (next) => {
                props.build(next);
            },
        },
    };
}
const claude = {
    model: "claude",
    options: {
        reference: true,
        separate: null
    },
    functions: [
        {
            name: "makeGroups",
            parameters: {
                description: " Properties containing the groups to be created for API\norganization\n\n------------------------------\n\nCurrent Type: {@link IAutoBeInterfaceGroupApplication.IProps}",
                type: "object",
                properties: {
                    groups: {
                        description: "Array of API endpoint groups for organizing development.\n\nDO: Organize groups around existing Prisma schema structure.\nDO: Provide complete coverage of all entities and requirements without\noverlap.",
                        type: "array",
                        items: {
                            $ref: "#/$defs/IAutoBeInterfaceGroupApplication.IGroup"
                        },
                        minItems: 1
                    }
                },
                required: [
                    "groups"
                ],
                additionalProperties: false,
                $defs: {
                    "IAutoBeInterfaceGroupApplication.IGroup": {
                        description: "Definition of a logical API endpoint group based on Prisma schema\norganization.\n\n**SCHEMA-BASED GROUP REQUIREMENTS:**\n\nDO: Derive groups from the Prisma schema structure rather than arbitrary\nbusiness domain names.\n\nThis ensures consistency with the underlying data model and prevents\nmisalignment between API organization and database structure.\n\n**Primary Group Sources (in order of priority):**\n\n1. **Prisma Schema Namespaces**: Use namespace names (e.g., `namespace\n   Shopping` \u2192 \"Shopping\")\n2. **Schema File Names**: Derive from file names (e.g., `shopping.prisma` \u2192\n   \"Shopping\")\n3. **Table Prefix Patterns**: Use consistent prefixes (e.g., `shopping_orders`\n   \u2192 \"Shopping\")\n4. **Schema Comments/Annotations**: Follow organizational comments in schema\n\n**Group Creation Guidelines:**\n\n- Each group covers specific Prisma schema entities without overlap\n- Size groups appropriately for manageable endpoint generation cycles\n- Maintain clear boundaries based on schema organization\n- Ensure complete coverage of all database entities and requirements\n- Related database tables within the same schema area are grouped together\n\n**When to Create Schema-Independent Groups:**\n\nOnly create groups that don't correspond to Prisma schema organization\nwhen:\n\n- Requirements include functionality not represented in any schema entity\n- Cross-cutting concerns span multiple schema areas\n- Integration operations don't map to specific database entities\n- System-level functionality requires dedicated API operations\n\n**Naming Standards:**\n\n- Use PascalCase format (e.g., \"Shopping\", \"BBS\", \"UserManagement\")\n- Names directly reflect Prisma schema structure\n- Keep names concise and schema-derived\n- Avoid arbitrary business domain names\n- Maintain consistency with schema organization\n\n**Quality Requirements:**\n\n- Groups collectively cover ALL entities and requirements\n- Each database entity belongs to exactly one group\n- Clear mapping to specific Prisma schema elements\n- Balance group sizes within schema constraints\n- Follow existing schema namespace or file structure patterns",
                        type: "object",
                        properties: {
                            name: {
                                description: "Unique identifier name derived from Prisma schema structure.\n\nDO: Correspond to schema namespaces, file names, table prefixes, or\norganizational annotations rather than arbitrary business domain names.",
                                type: "string",
                                minLength: 1
                            },
                            description: {
                                description: "Comprehensive description of the group's scope, schema foundation, and\npurpose.\n\n**Required Content:**\n\n1. Schema Foundation: Identify the Prisma schema elements defining this\n   group\n2. Database Entities: List specific tables and entities from the schema\n3. Functional Scope: Detail operations and workflows for schema entities\n4. Schema Relationships: Describe table relationships and dependencies\n5. Key Operations: Outline main operation types (CRUD, business processes)\n6. Requirements Mapping: Explain how requirements map to schema entities",
                                type: "string",
                                minLength: 1
                            }
                        },
                        required: [
                            "name",
                            "description"
                        ]
                    }
                }
            },
            description: "Generate logical groups for organizing API endpoint creation based on\nPrisma schema structure.\n\nDO: Derive groups from Prisma schema organization (namespaces, file\nstructure, table prefixes) rather than arbitrary business domains.\nDO: Create new groups only when existing schema structure cannot adequately\ncover all requirements.",
            validate: (() => { const _io0 = input => Array.isArray(input.groups) && (1 <= input.groups.length && input.groups.every(elem => "object" === typeof elem && null !== elem && _io1(elem))); const _io1 = input => "string" === typeof input.name && 1 <= input.name.length && ("string" === typeof input.description && 1 <= input.description.length); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.groups) || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "(Array<IAutoBeInterfaceGroupApplication.IGroup> & MinItems<1>)",
                    value: input.groups
                })) && ((1 <= input.groups.length || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "Array<> & MinItems<1>",
                    value: input.groups
                })) && input.groups.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
                    path: _path + ".groups[" + _index2 + "]",
                    expected: "IAutoBeInterfaceGroupApplication.IGroup",
                    value: elem
                })) && _vo1(elem, _path + ".groups[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
                    path: _path + ".groups[" + _index2 + "]",
                    expected: "IAutoBeInterfaceGroupApplication.IGroup",
                    value: elem
                })).every(flag => flag)) || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "(Array<IAutoBeInterfaceGroupApplication.IGroup> & MinItems<1>)",
                    value: input.groups
                })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.name && (1 <= input.name.length || _report(_exceptionable, {
                    path: _path + ".name",
                    expected: "string & MinLength<1>",
                    value: input.name
                })) || _report(_exceptionable, {
                    path: _path + ".name",
                    expected: "(string & MinLength<1>)",
                    value: input.name
                }), "string" === typeof input.description && (1 <= input.description.length || _report(_exceptionable, {
                    path: _path + ".description",
                    expected: "string & MinLength<1>",
                    value: input.description
                })) || _report(_exceptionable, {
                    path: _path + ".description",
                    expected: "(string & MinLength<1>)",
                    value: input.description
                })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
                if (false === __is(input)) {
                    errors = [];
                    _report = __typia_transform__validateReport._validateReport(errors);
                    ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeInterfaceGroupApplication.IProps",
                        value: input
                    })) && _vo0(input, _path + "", true) || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeInterfaceGroupApplication.IProps",
                        value: input
                    }))(input, "$input", true);
                    const success = 0 === errors.length;
                    return success ? {
                        success,
                        data: input
                    } : {
                        success,
                        errors,
                        data: input
                    };
                }
                return {
                    success: true,
                    data: input
                };
            }; })()
        }
    ]
};
const chatgpt = {
    model: "chatgpt",
    options: {
        reference: true,
        strict: false,
        separate: null
    },
    functions: [
        {
            name: "makeGroups",
            parameters: {
                description: " Properties containing the groups to be created for API\norganization\n\n------------------------------\n\nCurrent Type: {@link IAutoBeInterfaceGroupApplication.IProps}",
                type: "object",
                properties: {
                    groups: {
                        description: "Array of API endpoint groups for organizing development.\n\nDO: Organize groups around existing Prisma schema structure.\nDO: Provide complete coverage of all entities and requirements without\noverlap.\n\n\n@minItems 1",
                        type: "array",
                        items: {
                            $ref: "#/$defs/IAutoBeInterfaceGroupApplication.IGroup"
                        }
                    }
                },
                required: [
                    "groups"
                ],
                additionalProperties: false,
                $defs: {
                    "IAutoBeInterfaceGroupApplication.IGroup": {
                        description: "Definition of a logical API endpoint group based on Prisma schema\norganization.\n\n**SCHEMA-BASED GROUP REQUIREMENTS:**\n\nDO: Derive groups from the Prisma schema structure rather than arbitrary\nbusiness domain names.\n\nThis ensures consistency with the underlying data model and prevents\nmisalignment between API organization and database structure.\n\n**Primary Group Sources (in order of priority):**\n\n1. **Prisma Schema Namespaces**: Use namespace names (e.g., `namespace\n   Shopping` \u2192 \"Shopping\")\n2. **Schema File Names**: Derive from file names (e.g., `shopping.prisma` \u2192\n   \"Shopping\")\n3. **Table Prefix Patterns**: Use consistent prefixes (e.g., `shopping_orders`\n   \u2192 \"Shopping\")\n4. **Schema Comments/Annotations**: Follow organizational comments in schema\n\n**Group Creation Guidelines:**\n\n- Each group covers specific Prisma schema entities without overlap\n- Size groups appropriately for manageable endpoint generation cycles\n- Maintain clear boundaries based on schema organization\n- Ensure complete coverage of all database entities and requirements\n- Related database tables within the same schema area are grouped together\n\n**When to Create Schema-Independent Groups:**\n\nOnly create groups that don't correspond to Prisma schema organization\nwhen:\n\n- Requirements include functionality not represented in any schema entity\n- Cross-cutting concerns span multiple schema areas\n- Integration operations don't map to specific database entities\n- System-level functionality requires dedicated API operations\n\n**Naming Standards:**\n\n- Use PascalCase format (e.g., \"Shopping\", \"BBS\", \"UserManagement\")\n- Names directly reflect Prisma schema structure\n- Keep names concise and schema-derived\n- Avoid arbitrary business domain names\n- Maintain consistency with schema organization\n\n**Quality Requirements:**\n\n- Groups collectively cover ALL entities and requirements\n- Each database entity belongs to exactly one group\n- Clear mapping to specific Prisma schema elements\n- Balance group sizes within schema constraints\n- Follow existing schema namespace or file structure patterns",
                        type: "object",
                        properties: {
                            name: {
                                description: "Unique identifier name derived from Prisma schema structure.\n\nDO: Correspond to schema namespaces, file names, table prefixes, or\norganizational annotations rather than arbitrary business domain names.\n\n\n@minLength 1",
                                type: "string"
                            },
                            description: {
                                description: "Comprehensive description of the group's scope, schema foundation, and\npurpose.\n\n**Required Content:**\n\n1. Schema Foundation: Identify the Prisma schema elements defining this\n   group\n2. Database Entities: List specific tables and entities from the schema\n3. Functional Scope: Detail operations and workflows for schema entities\n4. Schema Relationships: Describe table relationships and dependencies\n5. Key Operations: Outline main operation types (CRUD, business processes)\n6. Requirements Mapping: Explain how requirements map to schema entities\n\n\n@minLength 1",
                                type: "string"
                            }
                        },
                        required: [
                            "name",
                            "description"
                        ]
                    }
                }
            },
            description: "Generate logical groups for organizing API endpoint creation based on\nPrisma schema structure.\n\nDO: Derive groups from Prisma schema organization (namespaces, file\nstructure, table prefixes) rather than arbitrary business domains.\nDO: Create new groups only when existing schema structure cannot adequately\ncover all requirements.",
            validate: (() => { const _io0 = input => Array.isArray(input.groups) && (1 <= input.groups.length && input.groups.every(elem => "object" === typeof elem && null !== elem && _io1(elem))); const _io1 = input => "string" === typeof input.name && 1 <= input.name.length && ("string" === typeof input.description && 1 <= input.description.length); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.groups) || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "(Array<IAutoBeInterfaceGroupApplication.IGroup> & MinItems<1>)",
                    value: input.groups
                })) && ((1 <= input.groups.length || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "Array<> & MinItems<1>",
                    value: input.groups
                })) && input.groups.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
                    path: _path + ".groups[" + _index2 + "]",
                    expected: "IAutoBeInterfaceGroupApplication.IGroup",
                    value: elem
                })) && _vo1(elem, _path + ".groups[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
                    path: _path + ".groups[" + _index2 + "]",
                    expected: "IAutoBeInterfaceGroupApplication.IGroup",
                    value: elem
                })).every(flag => flag)) || _report(_exceptionable, {
                    path: _path + ".groups",
                    expected: "(Array<IAutoBeInterfaceGroupApplication.IGroup> & MinItems<1>)",
                    value: input.groups
                })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.name && (1 <= input.name.length || _report(_exceptionable, {
                    path: _path + ".name",
                    expected: "string & MinLength<1>",
                    value: input.name
                })) || _report(_exceptionable, {
                    path: _path + ".name",
                    expected: "(string & MinLength<1>)",
                    value: input.name
                }), "string" === typeof input.description && (1 <= input.description.length || _report(_exceptionable, {
                    path: _path + ".description",
                    expected: "string & MinLength<1>",
                    value: input.description
                })) || _report(_exceptionable, {
                    path: _path + ".description",
                    expected: "(string & MinLength<1>)",
                    value: input.description
                })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
                if (false === __is(input)) {
                    errors = [];
                    _report = __typia_transform__validateReport._validateReport(errors);
                    ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeInterfaceGroupApplication.IProps",
                        value: input
                    })) && _vo0(input, _path + "", true) || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeInterfaceGroupApplication.IProps",
                        value: input
                    }))(input, "$input", true);
                    const success = 0 === errors.length;
                    return success ? {
                        success,
                        data: input
                    } : {
                        success,
                        errors,
                        data: input
                    };
                }
                return {
                    success: true,
                    data: input
                };
            }; })()
        }
    ]
};
const collection = {
    chatgpt,
    claude,
    llama: claude,
    deepseek: claude,
    "3.1": claude,
};
//# sourceMappingURL=orchestrateInterfaceGroups.js.map