

import { Entity, Column, PrimaryGeneratedColumn, ObjectIdColumn } from "typeorm";

const isMongoDB = process.env.DB_TYPE === "mongodb";

@Entity()
export class User {
  @ (isMongoDB ? ObjectIdColumn()  : PrimaryGeneratedColumn())
  id!: number | string;

  @Column({ unique: false })
  username!: string;

  @Column({ unique: true })
  email!: string;

  @Column()
  password!: string;

  @Column()
  salt?: string;

  @Column({nullable: true})
  githubId?:string;

  @Column({nullable: true})
  googleId?:string;

  @Column({ nullable: true })
  provider?: string;

  @Column({nullable: true})
  microsoftId?:string;

  @Column({ nullable: true })
  providerId?: string; 
  
  @Column()
  profileUrl?:string;
  
  @Column({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
  createdAt?: Date;

  @Column({
    type: "timestamp",
    default: () => "CURRENT_TIMESTAMP",
    onUpdate: "CURRENT_TIMESTAMP",
  })
  updatedAt?: Date;

  // Handling different ID strategies for MongoDB and SQL
  constructor() {
    if (isMongoDB) {
      (this as any).id = undefined; // MongoDB uses _id
    } else {
      (this as any).id = undefined; // SQL uses auto-increment
    }
  }
}
