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 { ShortUrl } from "src/app/model/entities/short-url";

@Injectable()
export class ShortUrlsColumns extends PageColumns<ShortUrl> {
  get(): TableColumn<ShortUrl>[] {
    return [
      ID_COLUMN,
      {
        name: "short_url",
        label: "short_url.short_url",
        type: "text",
        filterable: true,
        value: (row: ShortUrl) => row.shortUrl,
      },
      {
        name: "target_url",
        label: "short_url.target_url",
        type: "text",
        filterable: true,
        value: (row: ShortUrl) => row.targetUrl,
      },
      {
        name: "description",
        label: "common.description",
        type: "text",
        filterable: true,
        value: (row: ShortUrl) => row.description,
      },
      ...DB_MODEL_COLUMNS,
    ];
  }

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