import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { CollegeCampusEntity } from './CollegeCampus.entity';

@Index('UID', ['UID'], { unique: true })
@Index('instituteType', ['instituteType', 'active'], {})
@Entity('college', { schema: DB_SCHEMA })
export class CollegeEntity {
  @PrimaryGeneratedColumn({ type: 'smallint', name: 'collegeId' })
  collegeId: number;

  @Column('smallint', { name: 'by_user' })
  by_user: number;

  @Column('varchar', { name: 'UID', unique: true, length: 25 })
  UID: string;

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

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

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

  @Column('tinyint', {
    name: 'instituteType',
    comment: '1=college,2=university',
    width: 1,
  })
  instituteType: boolean;

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

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

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

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

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

  @Column('tinyint', { name: 'active', width: 1 })
  active: boolean;

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

  @Column('tinyint', { name: 'is_email_verified', width: 1 })
  is_email_verified: boolean;

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

  @Column('int', { name: 'upfileId' })
  upfileId: number;

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

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

  @OneToMany(() => CollegeCampusEntity, (campus) => campus.college)
  campus: CollegeCampusEntity[];
}
