<?php

namespace ModernFields\FieldGroups\Repositories;

use ModernFields\FieldGroups\Entities\Term;

/**
 * Term Repository
 * 
 * This class is responsible for retrieving term data from the database.
 * 
 * @since 1.0.0
 */
class TermRepository
{
  /**
   * Get a term by its ID and taxonomy.
   * 
   * @param int $term_id The ID of the term to retrieve.
   * @return Term|null The term object if found, null otherwise.
   */
  public static function getTermById(int $term_id): ?Term
  {
    $term = get_term($term_id);

    if (!$term || is_wp_error($term)) {
      return null;
    }

    return new Term($term);
  }
}
