<?php
/**
 * File Path: includes/helpers/cover-strategies/class-mbs-cover-strategy-default.php
 *
 * Cover Strategy — Book Default Cover (Level 3, FREE)
 *
 * Renders the book's default cover image using the WordPress featured image
 * (post_thumbnail / _thumbnail_id) stored via set_post_thumbnail(). Available
 * to all registered tiers (FREE and PRO). Delegates image markup to
 * MBS_Cover_Image_Builder with type 'default'.
 * Returns '' when no featured image is set or the attachment URL cannot
 * be resolved.
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Helpers/Cover_Strategies
 * @since      1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class MBS_Cover_Strategy_Default implements MBS_Cover_Strategy { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * @inheritDoc
	 */
	public static function resolve( int $post_id, ?object $format_row ): string {
		// Cover is stored as WordPress featured image by MBS_Book_Header_Cover.
		$default_cover_id = get_post_thumbnail_id( $post_id ); // R5-exempt: IS the MBS_Cover_Renderer default strategy
		if ( ! $default_cover_id ) {
			return '';
		}

		$cover_url = wp_get_attachment_url( $default_cover_id );
		if ( ! $cover_url ) {
			return '';
		}

		return MBS_Cover_Image_Builder::render( $cover_url, 'default', $post_id );
	}
}
