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

export type ActivityType = 'login' | 'logout' | 'biometric_auth' | 'location_update' | 'app_open' | 'app_close';
export type ActivityStatus = 'success' | 'failed' | 'blocked';

@Entity({ name: 'device_activity_log', schema: 'auth' })
export class DeviceActivityLog {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'device_id', type: 'uuid' })
  deviceId: string;

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

  // Actividad
  @Index()
  @Column({ name: 'activity_type', type: 'varchar', length: 50 })
  activityType: ActivityType;

  @Column({ name: 'activity_status', type: 'varchar', length: 20 })
  activityStatus: ActivityStatus;

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

  // Ubicacion
  @Column({ name: 'ip_address', type: 'inet', nullable: true })
  ipAddress: string;

  @Column({ type: 'decimal', precision: 10, scale: 8, nullable: true })
  latitude: number;

  @Column({ type: 'decimal', precision: 11, scale: 8, nullable: true })
  longitude: number;

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