import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserBranchEntity } from './UserBranch.entity';
import { UserEntity } from './User.entity';

@Index('center_code', ['center_code'], { unique: true })
@Index('center_code_2', ['center_code'], { unique: true })
@Index('center_name', ['center_name'], { unique: true })
@Entity('center_location', { schema: DB_SCHEMA })
export class CenterLocationEntity {
  @PrimaryGeneratedColumn({ type: 'tinyint', name: 'center_id' })
  center_id: number;

  @Column('tinyint', {
    name: 'physical_branch',
    nullable: true,
    width: 1,
    default: () => "'1'",
  })
  physical_branch: boolean | null;

  @Column('tinyint', {
    name: 'is_overseas',
    nullable: true,
    width: 1,
    default: () => "'0'",
  })
  is_overseas: boolean | null;

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

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

  @Column('char', {
    name: 'center_code',
    nullable: true,
    unique: true,
    length: 5,
  })
  center_code: string | null;

  @Column('smallint', { name: 'country_id', nullable: true })
  country_id: number | 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: 'zip_code', nullable: true, length: 10 })
  zip_code: string | null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  @OneToMany(() => UserBranchEntity, (userBranch) => userBranch.center)
  user_branches: UserBranchEntity[];

  @OneToMany(() => UserEntity, (user) => user.center_home)
  @JoinColumn({ name: 'center_id' })
  users_home: UserEntity[];
}
