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

export type InAppCategory = 'info' | 'success' | 'warning' | 'error' | 'task';
export type InAppPriority = 'low' | 'normal' | 'high' | 'urgent';
export type InAppActionType = 'link' | 'modal' | 'function';

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

  @Index()
  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

  @Index()
  @Column({ name: 'user_id', type: 'uuid' })
  userId: string;

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

  @Column({ name: 'message', type: 'text' })
  message: string;

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

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

  @Column({ name: 'action_type', type: 'varchar', length: 30, nullable: true })
  actionType: InAppActionType;

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

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

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

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

  @Column({ name: 'context_id', type: 'uuid', nullable: true })
  contextId: string;

  @Index()
  @Column({ name: 'is_read', type: 'boolean', default: false })
  isRead: boolean;

  @Column({ name: 'read_at', type: 'timestamptz', nullable: true })
  readAt: Date;

  @Column({ name: 'is_archived', type: 'boolean', default: false })
  isArchived: boolean;

  @Column({ name: 'archived_at', type: 'timestamptz', nullable: true })
  archivedAt: Date;

  @Column({ name: 'priority', type: 'varchar', length: 20, default: 'normal' })
  priority: InAppPriority;

  @Column({ name: 'expires_at', type: 'timestamptz', nullable: true })
  expiresAt: Date;

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