/**
 * Channel Entity
 * Notification delivery channel configuration
 * Compatible with erp-core channel.entity
 *
 * @module Notifications
 */

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

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

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

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

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

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

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

  @Column({ 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', nullable: true })
  rateLimitPerMinute: number;

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

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

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

  @Column({ name: 'is_default', type: 'boolean', default: false })
  isDefault: boolean;

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

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

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