export class SnapshotData {
  private constructor(
    public readonly rows: any[],
    public readonly summary: Record<string, any>,
    public readonly metadata: Record<string, any>,
  ) {}

  static create(params: {
    rows: any[];
    summary?: Record<string, any>;
    metadata?: Record<string, any>;
  }): SnapshotData {
    return new SnapshotData(
      params.rows,
      params.summary || {},
      params.metadata || {},
    );
  }

  getRowCount(): number {
    return this.rows.length;
  }

  isEmpty(): boolean {
    return this.rows.length === 0;
  }

  getSummary<T>(key: string, defaultValue?: T): T | undefined {
    return this.summary[key] ?? defaultValue;
  }

  getMetadata<T>(key: string, defaultValue?: T): T | undefined {
    return this.metadata[key] ?? defaultValue;
  }

  toJSON(): object {
    return {
      rows: this.rows,
      summary: this.summary,
      metadata: this.metadata,
      rowCount: this.getRowCount(),
    };
  }
}
