import {
  Entity, Column, PrimaryGeneratedColumn, CreateDateColumn,
  UpdateDateColumn, ManyToOne, JoinColumn,
} from 'typeorm';
import { User } from './user.entity';

export enum KycStatus { PENDING = 'pending', APPROVED = 'approved', REJECTED = 'rejected' }

@Entity('kyc_submissions')
export class KycSubmission {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column({ name: 'user_id', type: 'uuid' }) userId: string;
  @Column({ name: 'target_level', type: 'smallint' }) targetLevel: number;
  @Column({ name: 'full_name', type: 'varchar', length: 200, nullable: true }) fullName: string | null;
  @Column({ name: 'id_type', type: 'varchar', length: 20, nullable: true }) idType: string | null;
  @Column({ name: 'id_number', type: 'varchar', length: 50, nullable: true }) idNumber: string | null;
  @Column({ name: 'date_of_birth', type: 'date', nullable: true }) dateOfBirth: Date | null;
  @Column({ name: 'id_front_url', type: 'varchar', length: 500, nullable: true }) idFrontUrl: string | null;
  @Column({ name: 'id_back_url', type: 'varchar', length: 500, nullable: true }) idBackUrl: string | null;
  @Column({ name: 'selfie_url', type: 'varchar', length: 500, nullable: true }) selfieUrl: string | null;
  @Column({ type: 'text', nullable: true }) address: string | null;
  @Column({ name: 'annual_income', type: 'numeric', precision: 15, scale: 2, nullable: true }) annualIncome: number | null;
  @Column({ name: 'net_worth', type: 'numeric', precision: 15, scale: 2, nullable: true }) netWorth: number | null;
  @Column({ type: 'varchar', length: 20, default: 'pending' }) status: KycStatus;
  @Column({ name: 'reject_reason', type: 'varchar', length: 500, nullable: true }) rejectReason: string | null;
  @Column({ name: 'reviewed_by', type: 'uuid', nullable: true }) reviewedBy: string | null;
  @Column({ name: 'reviewed_at', type: 'timestamptz', nullable: true }) reviewedAt: Date | null;
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) createdAt: Date;
  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' }) updatedAt: Date;
  @ManyToOne(() => User) @JoinColumn({ name: 'user_id' }) user: User;
}
