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

/**
 * User ORM Entity - Database representation
 * This is the TypeORM entity with database-specific decorators
 */
@Entity('users')
@Index('idx_users_tenant', ['tenantId'])
@Index('idx_users_tenant_phone', ['tenantId', 'phone'])
@Index('idx_users_tenant_fingerprint', ['tenantId', 'fingerprint'])
export class UserORM {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

  @Column({
    type: 'varchar',
    length: 20,
    default: 'ANONYMOUS',
  })
  type: string;

  @Column({ type: 'varchar', length: 255, nullable: true })
  fingerprint: string | null;

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

  @Column({ type: 'varchar', length: 100, nullable: true })
  nickname: string | null;

  @Column({ type: 'varchar', length: 500, nullable: true })
  avatar: string | null;

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

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

  @Column({ name: 'last_active_at', type: 'timestamptz', default: () => 'NOW()' })
  lastActiveAt: Date;
}
