import { serializeAiExtractResponse } from './aiExtractResponse.js';
import { deserializeAiExtractResponse } from './aiExtractResponse.js';
import { serializeAiAgentInfo } from './aiAgentInfo.js';
import { deserializeAiAgentInfo } from './aiAgentInfo.js';
import { serializeDateTime } from '../internal/utils.js';
import { deserializeDateTime } from '../internal/utils.js';
import { BoxSdkError } from '../box/errors.js';
import { sdIsString } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export function serializeAiExtractStructuredResponse(val) {
    return {
        ['answer']: serializeAiExtractResponse(val.answer),
        ['created_at']: serializeDateTime(val.createdAt),
        ['completion_reason']: val.completionReason,
        ['confidence_score']: val.confidenceScore == void 0
            ? val.confidenceScore
            : Object.fromEntries(Object.entries(val.confidenceScore).map(([k, v]) => [
                k,
                (function (v) {
                    return v;
                })(v),
            ])),
        ['reference']: val.reference == void 0
            ? val.reference
            : Object.fromEntries(Object.entries(val.reference).map(([k, v]) => [
                k,
                (function (v) {
                    return v;
                })(v),
            ])),
        ['ai_agent_info']: val.aiAgentInfo == void 0
            ? val.aiAgentInfo
            : serializeAiAgentInfo(val.aiAgentInfo),
    };
}
export function deserializeAiExtractStructuredResponse(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "AiExtractStructuredResponse"',
        });
    }
    if (val.answer == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "answer" of type "AiExtractStructuredResponse" to be defined',
        });
    }
    const answer = deserializeAiExtractResponse(val.answer);
    if (val.created_at == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "created_at" of type "AiExtractStructuredResponse" to be defined',
        });
    }
    if (!sdIsString(val.created_at)) {
        throw new BoxSdkError({
            message: 'Expecting string for "created_at" of type "AiExtractStructuredResponse"',
        });
    }
    const createdAt = deserializeDateTime(val.created_at);
    if (!(val.completion_reason == void 0) &&
        !sdIsString(val.completion_reason)) {
        throw new BoxSdkError({
            message: 'Expecting string for "completion_reason" of type "AiExtractStructuredResponse"',
        });
    }
    const completionReason = val.completion_reason == void 0 ? void 0 : val.completion_reason;
    if (!(val.confidence_score == void 0) && !sdIsMap(val.confidence_score)) {
        throw new BoxSdkError({
            message: 'Expecting object for "confidence_score" of type "AiExtractStructuredResponse"',
        });
    }
    const confidenceScore = val.confidence_score == void 0
        ? void 0
        : sdIsMap(val.confidence_score)
            ? Object.fromEntries(Object.entries(val.confidence_score).map(([k, v]) => [
                k,
                (function (v) {
                    return v;
                })(v),
            ]))
            : {};
    if (!(val.reference == void 0) && !sdIsMap(val.reference)) {
        throw new BoxSdkError({
            message: 'Expecting object for "reference" of type "AiExtractStructuredResponse"',
        });
    }
    const reference = val.reference == void 0
        ? void 0
        : sdIsMap(val.reference)
            ? Object.fromEntries(Object.entries(val.reference).map(([k, v]) => [
                k,
                (function (v) {
                    return v;
                })(v),
            ]))
            : {};
    const aiAgentInfo = val.ai_agent_info == void 0
        ? void 0
        : deserializeAiAgentInfo(val.ai_agent_info);
    return {
        answer: answer,
        createdAt: createdAt,
        completionReason: completionReason,
        confidenceScore: confidenceScore,
        reference: reference,
        aiAgentInfo: aiAgentInfo,
    };
}
//# sourceMappingURL=aiExtractStructuredResponse.js.map