<?php
/**
 * File Path: includes/helpers/cover-strategies/class-mbs-cover-strategy-format.php
 *
 * Cover Strategy — Format-Specific Cover Image (Level 2, PRO)
 *
 * Renders the per-format cover image when a cover_image_id is set on the
 * format row. PRO-gated. Delegates image markup to MBS_Cover_Image_Builder,
 * passing the format type key so the correct CSS metaphor class is applied.
 * Returns '' when the site is not PRO, when no format row is supplied, when
 * cover_image_id is absent, or when 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_Format 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 {
		if ( ! mbs_is_pro() || ! $format_row || empty( $format_row->cover_image_id ) ) {
			return '';
		}

		$cover_url = wp_get_attachment_url( (int) $format_row->cover_image_id );
		if ( ! $cover_url ) {
			return '';
		}

		return MBS_Cover_Image_Builder::render(
			$cover_url,
			$format_row->format ?? 'other',
			$post_id
		);
	}
}
