<?php

namespace ModernFields\FieldGroups\Repositories;

use ModernFields\FieldGroups\Entities\Attachment;


/**
 * Attachment Repository
 * 
 * This class is responsible for retrieving attachment data from the database.
 * 
 * @since 1.0.0
 */
class AttachmentRepository
{
  /**
   * Get an attachment by its ID.
   * 
   * @param int $attachment_id The ID of the attachment to retrieve.
   * @return Attachment|null The attachment object if found, null otherwise.
   */
  public static function getAttachmentById($attachment_id): ?Attachment
  {
    $attachment = get_post($attachment_id);

    if (!$attachment || $attachment->post_type !== 'attachment') {
      return null;
    }

    return new Attachment($attachment);
  }
}
