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

import { Lead } from './lead.entity';
import { User } from '../../user/entities/user.entity';

/**
 * Minimal stand-in for your Laravel `Activity` model, scoped to leads only.
 * If you already have (or build) a generic polymorphic Activity table shared
 * across leads/clients/audits, drop this entity and point LeadService's
 * logActivity() calls at that instead — the log() call signature below was
 * kept intentionally close to `Activity::log($lead, $actorLabel, $message)`
 * so the swap is mostly a find-and-replace.
 */
@Entity('lead_activities')
@Index(['lead_id'])
export class LeadActivity {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ type: 'bigint', unsigned: true })
  lead_id: number;

  @ManyToOne(() => Lead, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'lead_id' })
  lead: Lead;

  @Column({ type: 'int', nullable: true })
  created_by: number | null;

  @ManyToOne(() => User, { nullable: true })
  @JoinColumn({ name: 'created_by' })
  creator: User | null;

  // e.g. 'System' or the acting user's display name at time of logging
  @Column({ type: 'varchar', length: 100 })
  actor_label: string;

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

  @CreateDateColumn({ name: 'happened_at' })
  happened_at: Date;
}
