import { Injectable, Provider } from '@angular/core';
import { Role } from 'src/app/model/entities/role';
import {
  DB_MODEL_COLUMNS,
  DESCRIPTION_COLUMN,
  ID_COLUMN,
  NAME_COLUMN,
  PageColumns,
} from 'src/app/core/base/page.columns';
import { TableColumn } from 'src/app/modules/shared/components/table/table.model';

@Injectable()
export class RolesColumns extends PageColumns<Role> {
  get(): TableColumn<Role>[] {
    return [
      ID_COLUMN,
      NAME_COLUMN,
      DESCRIPTION_COLUMN,
      {
        name: 'users',
        translationKey: 'sidebar.users',
        type: 'text',
        filterable: false,
        sortable: false,
        value: (row: Role) =>
          (row?.users ?? []).map(user => user.username).join(', '),
        width: '300px',
        visible: false,
      },
      ...DB_MODEL_COLUMNS,
    ];
  }

  static provide(): Provider[] {
    return [
      {
        provide: PageColumns,
        useClass: RolesColumns,
      },
      RolesColumns,
    ];
  }
}
