/**
 * WebhookEventType Entity
 * Event type definitions for webhook subscriptions
 * Compatible with erp-core event-type.entity
 *
 * @module Webhooks
 */

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

export type EventCategory = 'sales' | 'inventory' | 'customers' | 'auth' | 'billing' | 'system';

@Entity({ name: 'event_types', schema: 'webhooks' })
export class WebhookEventType {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index({ unique: true })
  @Column({ name: 'code', type: 'varchar', length: 100 })
  code: string;

  @Column({ name: 'name', type: 'varchar', length: 200 })
  name: string;

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

  @Index()
  @Column({ name: 'category', type: 'varchar', length: 50, nullable: true })
  category: EventCategory;

  @Column({ name: 'payload_schema', type: 'jsonb', default: {} })
  payloadSchema: Record<string, any>;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

  @Column({ name: 'is_internal', type: 'boolean', default: false })
  isInternal: boolean;

  @Column({ name: 'metadata', type: 'jsonb', default: {} })
  metadata: Record<string, any>;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
