/**
 * InAppNotification Entity
 * In-app notification with read/archive tracking
 * Compatible with erp-core in-app-notification.entity
 *
 * @module Notifications
 */

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({ type: 'varchar', length: 200 })
  title: string;

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

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

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

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

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

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

  @Column({ type: 'varchar', length: 30, default: 'info' })
  category: InAppCategory;

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

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

  @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({ 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;
}
