import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  Index,
} from 'typeorm';
import { SmsVerificationType } from './sms-verification.entity';

export enum SmsDeliveryStatus {
  PENDING = 'PENDING',
  SENT = 'SENT',
  DELIVERED = 'DELIVERED',
  FAILED = 'FAILED',
}

@Entity('sms_logs')
@Index('idx_sms_logs_phone', ['phone'])
@Index('idx_sms_logs_created', ['createdAt'])
export class SmsLog {
  @PrimaryGeneratedColumn('increment', { type: 'bigint' })
  id: string;

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

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

  @Column({ type: 'varchar', length: 20 })
  type: SmsVerificationType;

  @Column({ type: 'varchar', length: 20, default: SmsDeliveryStatus.PENDING })
  status: SmsDeliveryStatus;

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

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

  @Column({ name: 'error_msg', type: 'text', nullable: true })
  errorMsg: string | null;

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