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

@Index('designation_name', ['designation_name'], { unique: true })
@Entity('designation_masters', { schema: DB_SCHEMA })
export class DesignationMastersEntity {
  @PrimaryGeneratedColumn({ type: 'smallint', name: 'id' })
  id: number;

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

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

  @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;

  @OneToMany(() => UserEntity, (user) => user.designation)
  user: UserEntity[];
}
