// otp.entity.ts

import {
  Column,
  Entity,
} from "typeorm";
import { BaseEntity } from "@edr/api-common";

@Entity({
  // Table lives in the freight schema like every other freight entity. Without
  // this the entity inherits the DataSource default schema (public), so TypeORM
  // queries public.otp_verifications — which doesn't exist — and OTP verify
  // (e.g. the contract-signature sudo gate) fails with a 500 QueryFailedError.
  schema: "freight",
  name: "otp_verifications",
})
export class OtpVerification extends BaseEntity{
  // Exactly one of phone/email is set per row — the channel the code was sent
  // through.
  @Column({
    unique: true,
    nullable: true,
  })
  phone?: string;

  @Column({
    unique: true,
    nullable: true,
  })
  email?: string;

  @Column()
  otp!: string;

  @Column({
    default: false,
  })
  verified!: boolean;
}