import { describe, expect, it } from '@jest/globals';
import {
  a2uiReviewSubmitInfo,
  a2uiSubmitInfo,
  buildFormSubmitModelContent,
  buildReviewSubmitModelContent,
} from './ai-chat.submit-content';

describe('a2ui submit model content', () => {
  it('表单提交信息解析 submissionId 与 fieldErrors', () => {
    const info = a2uiSubmitInfo({
      a2uiSubmit: {
        formId: 'form-1',
        formTitle: '新增学生',
        values: { name: '张三' },
        submissionId: 'sub-1',
        fieldErrors: [{ field: 'phone', message: '手机号格式错误' }],
      },
    });
    expect(info).toEqual({
      formId: 'form-1',
      title: '新增学生',
      values: { name: '张三' },
      submissionId: 'sub-1',
      fieldErrors: [{ field: 'phone', message: '手机号格式错误' }],
    });
  });

  it('表单回灌内容包含提交 ID 与结构化错误', () => {
    const content = buildFormSubmitModelContent({
      title: '新增学生',
      values: { name: '张三' },
      submissionId: 'sub-1',
      fieldErrors: [],
    });
    expect(content).toContain('sub-1');
    expect(content).toContain('"name":"张三"');
    expect(content).toContain('fieldErrors');
  });

  it('审阅提交信息解析 submissionId 与下一步建议', () => {
    const info = a2uiReviewSubmitInfo({
      a2uiReviewSubmit: {
        reviewId: 'review-1',
        reviewTitle: '批量入住导入',
        resultMessage: '已导入 12 条',
        submissionId: 'sub-2',
        nextSteps: [{ key: 'after_checkin', label: '入住完成 → 建议录入费用' }],
      },
    });
    expect(info?.submissionId).toBe('sub-2');
    expect(info?.nextSteps).toHaveLength(1);
  });

  it('审阅回灌内容包含提交 ID 与下一步建议', () => {
    const content = buildReviewSubmitModelContent({
      reviewId: 'review-1',
      reviewTitle: '批量入住导入',
      resultMessage: '已导入 12 条',
      submissionId: 'sub-2',
      nextSteps: [{ key: 'after_checkin', label: '入住完成 → 建议录入费用' }],
    });
    expect(content).toContain('sub-2');
    expect(content).toContain('建议录入费用');
  });
});
