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

@Injectable()
export class GroupsColumns extends PageColumns<Group> {
  get(): TableColumn<Group>[] {
    return [
      ID_COLUMN,
      {
        name: 'name',
        translationKey: 'common.name',
        type: 'text',
        filterable: true,
        value: (row: Group) => row.name,
      },
      {
        name: 'roles',
        translationKey: 'common.roles',
        type: 'text',
        filterable: true,
        value: (row: Group) => row.roles.map(role => role.name).join(', '),
        width: '300px',
      },
      ...DB_MODEL_COLUMNS,
    ];
  }

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