import { EN_AppEntities } from '@app_consts';
import { AppBaseEntity } from './generic/app.baseentity';
import { AppBaseFilter } from './generic/app.baseentityfilter';
import { prepareArrayFromList, prepareListFromArray } from '@app_core/utils';

export class Employee extends AppBaseEntity {
  typeName = EN_AppEntities.Employee;
  get entitytitle(): string {  //is used for messages
    return this.entityId ? `Mitarbeiter "${this._name}"` : 'Neuen Mitarbeiter';
  }

  employeeId: number;
  employeeNo: string;
  salutation: string;
  firstName: string;
  lastName: string;
  shortName: string;
  title: string;
  position: string;
  loginName: string;
  email: string;
  rangId: number;
  clientId: number;
  mobilePhoneNo: string;
  phoneNo: string;
  isActive: boolean;

  mandantCode: string;

  departmentNamesList: string;
  departmentIdList: string;
  webappNamesList: string;
  webappIdList: string;
  attributeNamesList: string;
  attributeIdList: string;

  private _arAttributeIdList: number[];
  get arAttributeIdList(): number[] {
    return prepareArrayFromList(this, 'attributeIdList', '_arAttributeIdList');
  }

  set arAttributeIdList(array: number[]) {
    prepareListFromArray(this, 'attributeIdList', '_arAttributeIdList', array);
  }


  get _name(): string {
    return this.firstName ? this.firstName + ' ' : '' + this.lastName ? this.lastName : '';
  }


  public get fullname(): string {
    return this.firstName + ' ' + this.lastName;
  }

  public get entityId() {
    return this.employeeId;
  }
  public set entityId(value) {
    this.employeeId = value;
  }

  constructor(source?: Employee) {
    super(source);
    this.dontUpdateFields = [...this.dontUpdateFields,
      'departmentNamesList', 'departmentIdList', 'webappNamesList', 'webappIdList', 'attributeNamesList', 'attributeIdList', '_arAttributeIdList'];
    this.dontInsertFields = [...this.dontUpdateFields,
      'departmentNamesList', 'departmentIdList', 'webappNamesList', 'webappIdList', 'attributeNamesList', 'attributeIdList', '_arAttributeIdList'];
  }

  assign(source: Partial<Employee>): Employee {
    super.assign(source);
    return this;
  }

  clear() {
    super.clear();
    this._arAttributeIdList = undefined;
  }
}


export class EmployeeFullFilter extends AppBaseFilter {
  name: string;
  shortName: string;
  loginName: string;
  email: string;
  departmentIds: number[];
  attributeIds: number[];
  webappIds: number[];
  employeeId: number;
  clientId: number;
  isActive: boolean = true;
}

export class EmployeeFilter extends AppBaseFilter {
  employeeId: number;
}
