import { Column, Entity, PrimaryColumn } from 'typeorm';
import {
  encodeBigNumberKey,
  decodeBigNumberKey,
} from '../utils/big-number-key';

@Entity('event_actions', { schema: 'public' })
export class EventActionEntity {
  @PrimaryColumn('uuid', {
    name: 'id',
    nullable: false,
  })
  id: string;

  @Column({
    name: 'project_id',
    nullable: false,
    transformer: {
      from: (x) => encodeBigNumberKey(x),
      to: (x) => decodeBigNumberKey(x),
    },
  })
  projectId: string;

  @Column('uuid', {
    name: 'asset_id',
    nullable: false,
  })
  assetId: string;

  @Column('bigint', {
    name: 'target_block_key',
    nullable: true,
  })
  targetBlockKey: string | null;

  @Column('varchar', {
    name: 'target_prop',
    nullable: true,
  })
  targetProp: string | null;

  @Column('jsonb', {
    name: 'old_target_content',
  })
  oldTargetContent: Record<string, any>;

  @Column('jsonb', {
    name: 'new_target_content',
  })
  newTargetContent: Record<string, any>;

  @Column('varchar', {
    name: 'event_name',
    nullable: false,
  })
  eventName: string;

  @Column('timestamp with time zone', {
    name: 'created_at',
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
  })
  createdAt: Date;

  @Column('timestamp with time zone', {
    name: 'processed_at',
    nullable: true,
  })
  processedAt: Date | null;
}
