import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
} from 'typeorm';
import { Exclude } from 'class-transformer';

/**
 * User entity — represents an authenticated user of LexiBrain.
 * passwordHash and otpCode are excluded from all API responses.
 */
@Entity('user')
export class User {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ type: 'varchar', length: 255, unique: true })
  email!: string;

  /** bcryptjs hash — never returned in responses */
  @Exclude()
  @Column({ type: 'varchar', length: 255 })
  passwordHash!: string;

  /** True once the user has confirmed their email via OTP */
  @Column({ type: 'boolean', default: false })
  isVerified!: boolean;

  /** 6-digit OTP for email verification and password reset */
  @Exclude()
  @Column({ type: 'varchar', length: 6, nullable: true })
  otpCode!: string | null;

  /** Expiry timestamp for the current OTP (15 minutes) */
  @Column({ type: 'timestamp', nullable: true })
  otpExpiresAt!: Date | null;

  @CreateDateColumn()
  createdAt!: Date;
}
