import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { CityEntity } from './City.entity';
import { StateEntity } from './State.entity';
import { CountryEntity } from './Country.entity';
import { GenderEntity } from './Gender.entity';
import { DB_SCHEMA } from 'src/utils';

@Index('country_iso3_code', ['country_iso3_code', 'mobile', 'email'], {})
@Index('email', ['email'], { unique: true })
@Index('UID', ['UID'], { unique: true })
@Entity('students', { schema: DB_SCHEMA })
export class StudentsEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id' })
  id: number;

  @Column('tinyint', { name: 'active', width: 1, default: () => "'0'" })
  active: boolean;

  @Column('varchar', { name: 'OTP', nullable: true, length: 4 })
  OTP: string | null;

  @Column('tinyint', {
    name: 'is_otp_verified',
    width: 1,
    default: () => "'0'",
  })
  is_otp_verified: boolean;

  @Column('tinyint', {
    name: 'is_email_verified',
    width: 1,
    default: () => "'0'",
  })
  is_email_verified: boolean;

  @Column('tinyint', {
    name: 'is_verified',
    comment: '1=verified 0=unverified',
    width: 1,
    default: () => "'0'",
  })
  is_verified: boolean;

  @Column('tinyint', { name: 'profileUpdate', width: 1, default: () => "'0'" })
  profileUpdate: boolean;

  @Column('tinyint', { name: 'loggedIn', width: 1, default: () => "'0'" })
  loggedIn: boolean;

  @Column('varchar', { name: 'UID', nullable: true, unique: true, length: 10 })
  UID: string | null;

  @Column('tinyint', { name: 'reference_source_id', nullable: true })
  reference_source_id: number | null;

  @Column('varchar', { name: 'country_code', nullable: true, length: 5 })
  country_code: string | null;

  @Column('varchar', { name: 'country_iso3_code', nullable: true, length: 3 })
  country_iso3_code: string | null;

  @Column('varchar', { name: 'mobile', nullable: true, length: 20 })
  mobile: string | null;

  @Column('varchar', {
    name: 'email',
    nullable: true,
    unique: true,
    length: 60,
  })
  email: string | null;

  @Column('varchar', { name: 'fname', length: 60 })
  fname: string;

  @Column('varchar', { name: 'lname', length: 60 })
  lname: string;

  @Column('tinyint', { name: 'gender', nullable: true, width: 1 })
  gender: boolean | null;

  @Column('date', { name: 'dob', nullable: true })
  dob: string | null;

  @Column('date', { name: 'anniversary', nullable: true })
  anniversary: string | null;

  @Column('varchar', { name: 'profile_pic', nullable: true, length: 255 })
  profile_pic: string | null;

  @Column('varchar', { name: 'residential_address', length: 150 })
  residential_address: string;

  @Column('smallint', { name: 'country_id', nullable: true })
  country_id: number | null;

  @Column('tinyint', {
    name: 'mobile_notification',
    width: 1,
    default: () => "'1'",
  })
  mobile_notification: boolean;

  @Column('tinyint', {
    name: 'email_notification',
    width: 1,
    default: () => "'1'",
  })
  email_notification: boolean;

  @Column('varchar', { name: 'password', nullable: true, length: 32 })
  password: string | null;

  @Column('varchar', { name: 'plain_pwd', nullable: true, length: 20 })
  plain_pwd: string | null;

  @Column('smallint', { name: 'state_id', nullable: true })
  state_id: number | null;

  @Column('mediumint', { name: 'city_id', nullable: true })
  city_id: number | null;

  @Column('varchar', { name: 'passport_number', nullable: true, length: 20 })
  passport_number: string | null;

  @Column('date', { name: 'passport_expiry', nullable: true })
  passport_expiry: string | null;

  @Column('smallint', { name: 'profession_id', nullable: true })
  profession_id: number | null;

  @Column('smallint', { name: 'by_user', nullable: true })
  by_user: number | null;

  @Column('smallint', { name: 'aff_account_id', nullable: true })
  aff_account_id: number | null;

  @Column('smallint', { name: 'aff_by_user_id', nullable: true })
  aff_by_user_id: number | null;

  @Column('timestamp', { name: 'created', default: () => 'CURRENT_TIMESTAMP' })
  created: Date;

  @Column('timestamp', { name: 'modified', default: () => 'CURRENT_TIMESTAMP' })
  modified: Date;

  @ManyToOne(() => CityEntity)
  @JoinColumn({ name: 'city_id' })
  city: CityEntity;

  @ManyToOne(() => StateEntity)
  @JoinColumn({ name: 'state_id' })
  state: StateEntity;

  @ManyToOne(() => CountryEntity)
  @JoinColumn({ name: 'country_id' })
  country: CountryEntity;

  @ManyToOne(() => GenderEntity)
  @JoinColumn({ name: 'gender' })
  student_gender: GenderEntity;
}
