import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { UserPrivilegeConfigurationEntity } from '../../domain/entities/user-privilege-configuration.entity';
import { UserPrivilegeModel } from './user-privilege.model';

@Entity(TABLE_NAME.USER_PRIVILEGE_CONFIGURATION)
export class UserPrivilegeConfigurationModel
  extends BaseCoreModel<UserPrivilegeConfigurationEntity>
  implements UserPrivilegeConfigurationEntity
{
  @Column('varchar', { name: 'module', length: 125 })
  module: string;

  @Column('varchar', { name: 'module_label', length: 125, nullable: true })
  module_label: string;

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

  @Column('varchar', { name: 'menu_label', length: 125, nullable: true })
  menu_label: string;

  @Column('varchar', { name: 'sub_menu', length: 125, nullable: true })
  sub_menu: string;

  @Column('varchar', { name: 'sub_menu_label', length: 125, nullable: true })
  sub_menu_label: string;

  @Column('boolean', { nullable: true })
  view: boolean;

  @Column('boolean', { nullable: true })
  create: boolean;

  @Column('boolean', { nullable: true })
  edit: boolean;

  @Column('boolean', { nullable: true })
  delete: boolean;

  @Column('boolean', { nullable: true })
  cancel: boolean;

  @Column('boolean', { nullable: true })
  confirm: boolean;

  @Column('integer', { nullable: true, default: 0 })
  index: number;

  @Column('varchar', { name: 'user_privilege_id', nullable: true })
  user_privilege_id: string;
  @ManyToOne(
    () => UserPrivilegeModel,
    (model) => model.user_privilege_configurations,
    {
      onUpdate: 'CASCADE',
      onDelete: 'CASCADE',
    },
  )
  @JoinColumn({ name: 'user_privilege_id' })
  user_privilege: UserPrivilegeModel;
}
