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",
  label: "common.id",
  type: "number",
  filterable: true,
  value: (row: { id?: number }) => row.id,
  class: "max-w-24",
};

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

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

export const DELETED_COLUMN = {
  name: "deleted",
  label: "common.deleted",
  type: "bool",
  filterable: true,
  value: (row: DbModel) => row.deleted,
};

export const EDITOR_COLUMN = {
  name: "editor",
  label: "common.editor",
  value: (row: DbModel) => row.editor?.username,
};

export const CREATED_UTC_COLUMN = {
  name: "createdUtc",
  label: "common.created",
  type: "date",
  value: (row: DbModel) => row.createdUtc,
  class: "max-w-32",
};

export const UPDATED_UTC_COLUMN = {
  name: "updatedUtc",
  label: "common.updated",
  type: "date",
  value: (row: DbModel) => row.updatedUtc,
  class: "max-w-32",
};

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