import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  PrimaryGeneratedColumn,
} from 'typeorm';

/**
 * A2UI 提交幂等记录：同一 artifact + clientRequestId 只允许执行一次，
 * 重复提交返回既有结果，避免双击/重试导致二次写入或二次生成。
 */
@Entity('ai_a2ui_submissions')
@Index('uk_ai_a2ui_submissions_artifact_client', ['artifactId', 'clientRequestId'], {
  unique: true,
})
export class AiA2uiSubmission {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'artifact_id', type: 'varchar', length: 100 })
  artifactId: string;

  @Column({ name: 'client_request_id', type: 'varchar', length: 36 })
  clientRequestId: string;

  @Column({ type: 'varchar', length: 20 })
  status: string;

  @Column({ name: 'result_json', type: 'text', nullable: true })
  resultJson: string | null;

  @CreateDateColumn({ name: 'created_at', type: 'datetime' })
  createdAt: Date;
}
