/**
 * Webhook ORM Entity
 */

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

@Entity('webhooks')
@Index(['organization_id', 'status'])
export class WebhookOrmEntity {
  @PrimaryColumn('uuid')
  id: string;

  @Column('uuid')
  organization_id: string;

  @Column('varchar', { length: 500 })
  url: string;

  @Column('simple-array')
  events: string[];

  @Column('varchar', { length: 255 })
  secret: string;

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

  @Column('text', { nullable: true })
  description?: string;

  @Column('jsonb', { nullable: true })
  headers?: Record<string, string>;

  @Column('int', { default: 0 })
  retry_count: number;

  @Column('timestamp', { nullable: true })
  last_triggered_at?: Date;

  @Column('int', { default: 0 })
  failure_count: number;

  @CreateDateColumn()
  created_at: Date;

  @UpdateDateColumn()
  updated_at: Date;
}
