import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { TimezoneMastersEntity } from './TimezoneMasters.entity';
import { VisaServiceMasterEntity } from './VisaServiceMaster.entity';
import { VcmCommissionContractsEntity } from './VcmCommissionContracts.entity';

@Index('active', ['active'], {})
@Entity('country', { schema: DB_SCHEMA })
export class CountryEntity {
  @PrimaryGeneratedColumn({ type: 'smallint', name: 'country_id' })
  country_id: number;

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

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

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

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

  @Column('varchar', { name: 'currency_code', length: 5 })
  currency_code: string;

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

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

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

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

  @Column('tinyint', {
    name: 'passport_length_min',
    nullable: true,
    default: () => "'8'",
  })
  passport_length_min: number | null;

  @Column('tinyint', {
    name: 'passport_length_max',
    nullable: true,
    default: () => "'15'",
  })
  passport_length_max: number | null;

  @Column('enum', {
    name: 'otp_medium',
    comment: '1=Email, 2=Mobile',
    enum: ['1', '2'],
    default: () => "'1'",
  })
  otp_medium: '1' | '2';

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

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

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

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

  @OneToMany(() => TimezoneMastersEntity, (timezone) => timezone.country)
  timezones: TimezoneMastersEntity[];

  @OneToMany(() => VisaServiceMasterEntity, (vsm) => vsm.country)
  visa_service_master: VisaServiceMasterEntity[];

  @OneToMany(() => VcmCommissionContractsEntity, (vcm) => vcm.visa_country)
  visa_commission_contract: VcmCommissionContractsEntity[];
}
