import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from '../../domain/entities/user.entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { UserLoginEntity } from '../../domain/entities/user-login.entity';
import { UserModel } from './user.model';
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { UserRole } from '../../constants';
import { AppSource } from 'src/core/helpers/constant';

@Entity(TABLE_NAME.USER_LOGIN)
export class UserLoginModel
  extends BaseCoreModel<UserEntity>
  implements UserLoginEntity
{
  @Column({ type: 'bigint', nullable: false })
  login_date: number;

  @Column({ type: 'varchar', name: 'login_token', nullable: true })
  login_token: string;

  @Column('varchar', { name: 'user_id', nullable: true })
  user_id: string;

  @Column({ type: 'uuid', nullable: true })
  item_id: string;

  @Column({ type: 'varchar', nullable: true })
  item_name: string;

  @Column({ type: 'enum', enum: UserRole, nullable: true })
  role: UserRole;

  @Column({ type: 'enum', enum: AppSource, nullable: true })
  source: AppSource;

  @ManyToOne(() => UserModel, (model) => model.user_login, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
    nullable: false,
    orphanedRowAction: 'delete',
  })
  @JoinColumn({ name: 'user_id' })
  user: UserModel;
}
