import { BaseEntity } from '../../base/entity/base.js';
import { Column, Entity, Index } from 'typeorm';

/**
 * Session tree entries stored for the MySQL provider.
 */
@Index(['sessionId', 'entryId'], { unique: true })
@Index(['sessionId', 'parentEntryId'])
@Index(['sessionId', 'timestamp'])
@Index(['sessionId', 'timestamp', 'entrySeq', 'entryId'])
@Index(['type'])
@Entity('netaclaw_agent_session_entry')
export class NetaClawAgentSessionEntryEntity extends BaseEntity {
  @Column({ comment: 'Session tree session id' })
  sessionId: string;

  @Column({ comment: 'Pi entry id, not the BaseEntity primary key', length: 255 })
  entryId: string;

  @Column({ comment: 'Pi parent entry id, not the BaseEntity primary key', length: 255, nullable: true })
  parentEntryId: string | null;

  @Column({ comment: 'Append order within the session', default: 0 })
  entrySeq: number;

  @Column({ comment: 'Pi entry timestamp (ISO string)', length: 64 })
  timestamp: string;

  @Column({ comment: 'Entry type', length: 100 })
  type: string;

  @Column({ type: 'json', comment: 'Full entry payload or non-indexed fields', nullable: true })
  payload: Record<string, unknown> | null;

  @Column({ type: 'json', comment: 'Entry metadata', nullable: true })
  metadata: Record<string, unknown> | null;
}
