import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { AuthRoleAttr } from "./AuthRoleAttr";
import { PosMaster } from "./PosMaster";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeeTempPosMaster } from "./EmployeeTempPosMaster";

@Entity("authRole")
export class AuthRole extends EntityBase {
  @Column({
    nullable: true,
    comment: "ชื่อบทบาท",
    length: 255,
    default: null,
  })
  roleName: string;

  @Column({
    nullable: true,
    comment: "รายละเอียด",
    length: 255,
    default: null,
  })
  roleDescription: string;

  @Column({
    nullable: true,
    comment: "ข้อมูลที่ role admin สามารถเห็นได้",
    default: null,
  })
  isAdminVisibled: boolean;

  @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole)
  authRoles: AuthRoleAttr[];

  @OneToMany(() => PosMaster, (posMaster) => posMaster.authRole)
  posMasters: PosMaster[];

  @OneToMany(() => EmployeePosMaster, (posMasters) => posMasters.authRole)
  posMasterEmps: EmployeePosMaster[];

  @OneToMany(() => EmployeeTempPosMaster, (posMasters) => posMasters.authRole)
  posMasterEmpTemps: EmployeeTempPosMaster[];
}

export class CreateAuthRole {
  @Column()
  roleName: string;

  @Column()
  roleDescription: string;
}

export type UpdateAuthRole = Partial<CreateAuthRole>;

export class CreateAddAuthRole {
  @Column()
  authRoleId: string;

  @Column()
  posMasterId: string;
}
