<?php
/**
 * The default RSS Feed format
 *
 * Fields are returned without modification. Extend this entity and override
 * methods to modify supported fields. Add the "mode" request variable with the
 * name matching the desired format to enable that feed format.
 */

declare(strict_types=1);

namespace WP_AUX\Entities\RssFeed;

use WP_AUX\Services\HtmlService;

class RssFeedEntity
{
  public static $name = 'default';

  public function itemExcerpt($excerpt): string
  {
    return $excerpt;
  }

  public function itemContent($content): string
  {
    return $content;
  }

  public function itemExcerptAppendDetails(string $excerpt): string
  {
    $excerpt = HtmlService::paragraph($excerpt);

    $url = get_the_permalink();
    $title = get_the_title_rss();
    $homeUrl = home_url();
    $homeTitle = get_bloginfo('blogname');

    $excerpt .= <<<HTML
    <p>The post <a href="{$url}">{$title}</a> appeared first on <a href="{$homeUrl}">{$homeTitle}</a>.</p>
HTML;

    return $excerpt;
  }

  public static function create(): static
  {
    return new static();
  }
}
