<?php

namespace Drupal\api_monitor_client;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;

/**
 * Provides a list controller for api_monitor_manual entities.
 */
class ApiMonitorManualListBuilder extends EntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader(): array {
    $header['title'] = $this->t('Title');
    $header['api_id'] = $this->t('API ID');
    $header['provider'] = $this->t('Provider');
    $header['method'] = $this->t('Method');
    $header['status'] = $this->t('Status');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity): array {
    /** @var \Drupal\api_monitor_client\Entity\ApiMonitorManualInterface $entity */
    $row['title'] = $entity->toLink();
    $row['api_id'] = $entity->getApiId();

    $provider = $entity->getProvider();
    $row['provider'] = $provider ? $provider->label() : '-';
    $row['method'] = $entity->getMethod();
    $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished');

    return $row + parent::buildRow($entity);
  }

}
