"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRealizeWriteInputType = getRealizeWriteInputType;
const utils_1 = require("@autobe/utils");
/**
 * Generate TypeScript type definition string for provider function props
 *
 * This utility creates the exact props interface that the Realize Agent's
 * generated provider functions must accept. It combines:
 *
 * - Authentication context (user/admin/member from authorization)
 * - URL path parameters (e.g., id, boardId, postId)
 * - Request body type (if applicable)
 *
 * The output is injected into REALIZE_WRITE_ARTIFACT.md template to tell the AI
 * exactly what parameter type the function should accept.
 *
 * @example
 *   // For DELETE /posts/:id (authenticated)
 *   // Returns: "props: { user: IUser; id: string & tags.Format<'uuid'>; }"
 *
 * @example
 *   // For GET /public/info (no auth, no params)
 *   // Returns: "// No props parameter needed - function should have no parameters"
 *
 * @param operation - OpenAPI operation definition containing parameters and
 *   auth requirements
 * @param authorization - Authorization context with user/role information (if
 *   authenticated endpoint)
 * @returns TypeScript interface string like "props: { user: IUser; id: string;
 *   body: IRequest; }"
 */
function getRealizeWriteInputType(operation, authorization) {
    var _a, _b;
    const functionParameterFields = [];
    // Add authentication field (user/admin/member) if endpoint requires auth
    const hasAuthentication = authorization && operation.authorizationRole;
    if (hasAuthentication) {
        const authFieldName = operation.authorizationRole;
        const authFieldType = authorization.payload.name;
        functionParameterFields.push(`${authFieldName}: ${authFieldType};`);
    }
    // Add URL path parameters (e.g., /posts/:id → id parameter)
    const pathParameters = operation.parameters;
    pathParameters.forEach((pathParam) => {
        const paramName = pathParam.name;
        const paramType = pathParam.schema.type;
        const paramFormat = "format" in pathParam.schema
            ? ` & tags.Format<'${pathParam.schema.format}'>`
            : "";
        const parameterField = `${paramName}: ${paramType}${paramFormat};`;
        functionParameterFields.push(parameterField);
    });
    // Add request body if present (POST/PUT/PATCH operations)
    const hasRequestBody = (_a = operation.requestBody) === null || _a === void 0 ? void 0 : _a.typeName;
    if (hasRequestBody) {
        const bodyTypeName = (_b = operation.requestBody) === null || _b === void 0 ? void 0 : _b.typeName;
        functionParameterFields.push(`body: ${bodyTypeName};`);
    }
    // Format as TypeScript props interface or indicate no parameters needed
    const hasParameters = functionParameterFields.length > 0;
    if (!hasParameters) {
        return `// No props parameter needed - function should have no parameters`;
    }
    const formattedFields = functionParameterFields
        .map((field) => `  ${field}`)
        .join("\n");
    return utils_1.StringUtil.trim `
    props: {
    ${formattedFields}
    }`;
}
//# sourceMappingURL=getRealizeWriteInputType.js.map