import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { CollegeEntity } from './College.entity';

@Index(
  'instituteid',
  [
    'instituteid',
    'campusAssociationTypeId',
    'country_id',
    'state_id',
    'city_id',
  ],
  {},
)
@Entity('college_campus', { schema: DB_SCHEMA })
export class CollegeCampusEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

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

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

  @Column('varchar', { name: 'campName', length: 255 })
  campName: string;

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

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

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

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

  @Column('mediumint', { name: 'city_id' })
  city_id: number;

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

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

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

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

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

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

  @ManyToOne(() => CollegeEntity, (college) => college.campus)
  @JoinColumn({ name: 'instituteid' })
  college: CollegeEntity;
}
