<?php
namespace Bookaro\Utils;

defined( 'ABSPATH' ) || exit;

/**
 * Decision logic + constants for the WordPress.org review prompt shown to
 * site owners.
 *
 * Kept free of WordPress calls so the trigger rules are unit-testable in
 * isolation; the controller (ReviewNudgeController) resolves the real WP
 * state and feeds it in.
 */
final class ReviewPrompt
{
    /** Completed-bookings threshold before the prompt is first shown. */
    public const DEFAULT_THRESHOLD = 5;

    /** Per-user meta flag set once the owner dismisses or acts on the prompt. */
    public const DISMISSED_META_KEY = 'bookaro_review_nudge_dismissed';

    /** Canonical WordPress.org "leave a review" URL for this plugin. */
    public const REVIEW_URL = 'https://wordpress.org/support/plugin/mybookaro/reviews/#new-post';

    /**
     * Whether the review prompt should be displayed.
     *
     * Pure predicate: every input is resolved by the caller so this stays
     * unit-testable without WordPress.
     *
     * @param bool $can_manage      Current user can manage MyBookaro admin.
     * @param bool $dismissed       User already dismissed/acted on the prompt.
     * @param int  $completed_count Site-wide count of completed bookings.
     * @param int  $threshold       Completed-bookings threshold (must be >= 1).
     */
    public static function should_display(
        bool $can_manage,
        bool $dismissed,
        int $completed_count,
        int $threshold
    ): bool {
        if ( ! $can_manage || $dismissed ) {
            return false;
        }
        if ( $threshold < 1 ) {
            return false;
        }
        return $completed_count >= $threshold;
    }
}
