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

@Entity('event_webhook_logs', { schema: 'public' })
export class EventWebhookLogEntity {
  @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('timestamp with time zone', {
    name: 'actions_from',
    nullable: false,
  })
  actionsFrom: Date;

  @Column('timestamp with time zone', {
    name: 'actions_to',
    nullable: false,
  })
  actionsTo: Date;

  @Column('timestamp with time zone', {
    name: 'request_at',
    nullable: false,
  })
  requestAt: Date;

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

  @Column('smallint', {
    name: 'response_status_code',
    nullable: true,
  })
  responseStatusCode: number | null;

  @Column('smallint', {
    name: 'attempt',
    nullable: true,
  })
  attempt: number;

  @Column('text', {
    name: 'response_error',
    nullable: true,
  })
  responseError: string;
}
