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: 'target_url',
        translationKey: 'short_url.target_url',
        type: 'text',
        filterable: true,
        value: (row: ShortUrl) => row.targetUrl,
      },
      {
        name: 'description',
        translationKey: 'common.description',
        type: 'text',
        filterable: true,
        value: (row: ShortUrl) => row.description,
      },
      {
        name: 'visits',
        translationKey: 'short_url.visits',
        type: 'number',
        filterable: true,
        value: (row: ShortUrl) => row.visits,
        class: 'highlight2',
      },
      {
        name: 'loading_screen',
        translationKey: 'short_url.loading_screen',
        type: 'boolean',
        filterable: true,
        value: (row: ShortUrl) => row.loadingScreen,
      },
      {
        name: 'domain',
        translationKey: 'common.domain',
        type: 'text',
        filterable: true,
        value: (row: ShortUrl) => row.domain?.name,
      },
      ...DB_MODEL_COLUMNS,
    ];
  }

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