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

@Index('division_name', ['division_name'], { unique: true })
@Entity('division_masters', { schema: DB_SCHEMA })
export class DivisionMastersEntity {
  @PrimaryGeneratedColumn({ type: 'tinyint', name: 'id' })
  id: number;

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

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

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

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

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

  @OneToMany(() => UserDivisionsEntity, (userDivision) => userDivision.division)
  user_divisions: UserDivisionsEntity[];
}
