<?php
/**
 * Percentage discount reward type implementation.
 *
 * Lite version: Provides only presentation/UI methods.
 * Full functionality (issue, claim, redeem) is available in Pro version.
 *
 * @package Awesomemotive\Rewardswp\RewardTypes
 * @since 1.0.0
 */

namespace Awesomemotive\Rewardswp\RewardTypes;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractRewardType;
use Awesomemotive\Rewardswp\Models\Reward;

/**
 * Percentage Discount Reward Type
 *
 * This is the Lite version that provides only presentation methods.
 * The Pro version (ProPercentageDiscountRewardType) extends this class
 * and adds full coupon functionality via traits.
 *
 * @since 1.0.0
 */
class PercentageDiscountRewardType extends AbstractRewardType {
	/**
	 * Get reward type slug.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_type(): string {
		return 'percentage_discount';
	}

	/**
	 * Get admin title.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_admin_title(): string {
		return __( 'Percentage off', 'rewardswp' );
	}

	/**
	 * Get panel title.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_panel_title(): string {
		if ( is_a( $this->reward, Reward::class ) ) {
			// Formatted amount already includes the percentage label (e.g., "10% off coupon").
			return $this->get_reward_formatted_amount();
		}

		return __( 'Discount coupon', 'rewardswp' );
	}

	/**
	 * Get panel instructions.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_panel_instructions(): string {
		return __( 'Use this coupon on your next order!', 'rewardswp' );
	}

	/**
	 * Get icon name.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_icon_name(): string {
		return 'reward-percentage-coupon';
	}

	/**
	 * Get supported integrations.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public function available_for(): array {
		return [
			'woocommerce',
			'easy_digital_downloads',
		];
	}

	/**
	 * Get default configuration.
	 *
	 * @since 1.0.0
	 *
	 * @return int[]
	 */
	public function get_defaults(): array {
		return [
			'reward_amount'        => 10,
			'minimum_order_amount' => 0,
			'reward_expiration'    => '+3 months',
		];
	}

	/**
	 * Get admin title for advocate.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_admin_advocate_title(): string {
		return __( 'Reward Advocates with a Percentage Discount', 'rewardswp' );
	}

	/**
	 * Get admin title for friend.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_admin_friend_title(): string {
		return __( 'Reward Friends with a Percentage Discount', 'rewardswp' );
	}

	/**
	 * Retrieve the reward formatted amount.
	 *
	 * @since 1.0.0
	 *
	 * @param float  $amount  Optional. Reward amount to format. Default 0 (uses attached reward amount when available).
	 * @param string $format  Optional. Format identifier. Accepts 'default' (includes coupon suffix) or 'value_only'. Default 'default'.
	 *
	 * @return string
	 */
	public function get_reward_formatted_amount( float $amount = 0, string $format = 'default' ): string {
		if ( empty( $amount ) && is_a( $this->reward, Reward::class ) ) {
			$amount = $this->reward->amount;
		}

		if ( empty( $amount ) ) {
			return '';
		}

		switch ( $format ) {
			case 'value_only':
				return sprintf(
					/* translators: %s is the discount percentage. */
					__( '%s%% off', 'rewardswp' ),
					$amount
				);
			default:
				return sprintf(
					/* translators: %s is the discount percentage. */
					__( '%s%% off coupon', 'rewardswp' ),
					$amount
				);
		}
	}

	/**
	 * Lite stub: Issue reward not available.
	 *
	 * @since 1.0.0
	 *
	 * @param \Awesomemotive\Rewardswp\Models\Referral $referral Referral instance.
	 * @param string                                   $recipient_type Recipient type.
	 * @param array                                    $args Arguments.
	 *
	 * @return \Awesomemotive\Rewardswp\Models\Reward|null
	 */
	public function issue_reward( \Awesomemotive\Rewardswp\Models\Referral $referral, string $recipient_type, array $args = [] ): ?\Awesomemotive\Rewardswp\Models\Reward {
		return null;
	}

	/**
	 * Lite stub: Claim reward not available.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Arguments.
	 *
	 * @return \Awesomemotive\Rewardswp\Models\Reward|null
	 */
	public function claim_reward( array $args = [] ): ?\Awesomemotive\Rewardswp\Models\Reward {
		return null;
	}

	/**
	 * Lite stub: Redeem reward not available.
	 *
	 * @since 1.0.0
	 *
	 * @param \Awesomemotive\Rewardswp\Models\Reward $reward Reward instance.
	 * @param array                                  $args Arguments.
	 *
	 * @return bool|null
	 */
	public function redeem_reward( \Awesomemotive\Rewardswp\Models\Reward $reward, array $args = [] ): ?bool {
		return false;
	}

	/**
	 * Lite stub: Prepare rewards not available.
	 *
	 * @since 1.0.0
	 *
	 * @param \Awesomemotive\Rewardswp\Models\Reward[] $rewards Rewards array.
	 * @param array                                    $args Arguments.
	 *
	 * @return array
	 */
	public function prepare_rewards_objects_for_view( array $rewards, array $args = [] ): array {
		return [];
	}

	/**
	 * Lite stub: Empty rewards content not available.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_empty_rewards_content(): string {
		return '';
	}

	/**
	 * Lite stub: Claim panel content not available.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Arguments.
	 *
	 * @return string
	 */
	public function get_claim_panel_content( array $args = [] ): string {
		return '';
	}

	/**
	 * Lite stub: Panel subtitle not available.
	 *
	 * @since 1.0.0
	 *
	 * @param \Awesomemotive\Rewardswp\Models\Reward|null $reward Reward instance.
	 *
	 * @return string
	 */
	public function get_panel_subtitle( ?\Awesomemotive\Rewardswp\Models\Reward $reward = null ): string {
		return '';
	}
}
