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

export type ChannelType = 'email' | 'sms' | 'push' | 'whatsapp' | 'in_app' | 'webhook';

@Entity({ name: 'channels', schema: 'notifications' })
export class Channel {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

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

  @Column({ name: 'channel_type', type: 'varchar', length: 30 })
  channelType: ChannelType;

  @Column({ name: 'provider', type: 'varchar', length: 50, nullable: true })
  provider: string;

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

  @Column({ name: 'rate_limit_per_minute', type: 'int', default: 60 })
  rateLimitPerMinute: number;

  @Column({ name: 'rate_limit_per_hour', type: 'int', default: 1000 })
  rateLimitPerHour: number;

  @Column({ name: 'rate_limit_per_day', type: 'int', default: 10000 })
  rateLimitPerDay: number;

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

  @Column({ name: 'is_default', type: 'boolean', default: false })
  isDefault: 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;
}
