import { Injectable } from '@angular/core';
import { TableColumn } from 'src/app/modules/shared/components/table/table.model';
import { DbModel } from 'src/app/model/entities/db-model';

@Injectable({
  providedIn: 'root',
})
export abstract class PageColumns<T> {
  abstract get(): TableColumn<T>[];
}

export const ID_COLUMN = {
  name: 'id',
  translationKey: 'common.id',
  type: 'number',
  filterable: true,
  sortable: true,
  value: (row: { id?: number }) => row.id,
  class: 'max-w-24',
};

export const NAME_COLUMN = {
  name: 'name',
  translationKey: 'common.name',
  type: 'text',
  filterable: true,
  sortable: true,
  value: (row: { name?: string }) => row.name,
};

export const DESCRIPTION_COLUMN = {
  name: 'description',
  translationKey: 'common.description',
  type: 'text',
  filterable: true,
  sortable: true,
  value: (row: { description?: string }) => row.description,
};

export const DELETED_COLUMN = {
  name: 'deleted',
  translationKey: 'common.deleted',
  type: 'bool',
  filterable: false,
  sortable: true,
  value: (row: DbModel) => row.deleted,
  visible: false,
};

export const EDITOR_COLUMN = {
  name: 'editor',
  translationKey: 'common.editor',
  type: 'text',
  filterable: true,
  value: (row: DbModel) => row.editor?.username,
  filterSelector: (mode: string, value: unknown) => {
    return { editor: { username: { [mode]: value } } };
  },
  class: 'max-w-32',
  visible: false,
};

export const CREATED_UTC_COLUMN = {
  name: 'created',
  translationKey: 'common.created',
  type: 'date',
  filterable: true,
  sortable: true,
  value: (row: DbModel) => row.created,
  class: 'max-w-32',
  visible: false,
};

export const UPDATED_UTC_COLUMN = {
  name: 'updated',
  translationKey: 'common.updated',
  type: 'date',
  filterable: true,
  sortable: true,
  value: (row: DbModel) => row.updated,
  class: 'max-w-32',
  visible: false,
};

export const DB_MODEL_COLUMNS = [
  DELETED_COLUMN,
  EDITOR_COLUMN,
  CREATED_UTC_COLUMN,
  UPDATED_UTC_COLUMN,
];
