<?php

namespace WeDevs\AppBridge\Integrations\WPERP;

use WeDevs\AppBridge\Core\AbstractLicenseManager;
use WeDevs\AppBridge\Core\Contracts\LicenseBackend;
use WeDevs\AppBridge\Core\License\EddSlBackend;

/**
 * WP ERP App license manager.
 *
 * The WP ERP App is sold and licensed from our own EDD Software Licensing
 * store (wperp.com) — both standalone and bundled inside the ERP Pro Scale
 * package — so this integration validates against EDD SL directly rather
 * than through Appsero.
 */
class LicenseManager extends AbstractLicenseManager {

	/**
	 * EDD download IDs for the "ERP App" plans on wperp.com.
	 *
	 * Each billing plan is a separate EDD download, so a key may belong to any
	 * of these. Activation tries each until one validates — the plan is
	 * resolved server-side from the key alone, with no plan choice in the UI.
	 */
	const ITEM_IDS = [
		175874, // Monthly.
		176022, // Yearly.
		176085, // Lifetime.
	];

	/**
	 * Default EDD store base URL.
	 */
	const STORE_URL = 'https://wperp.com';

	/**
	 * Use the EDD Software Licensing backend instead of Appsero.
	 */
	protected function make_backend(): LicenseBackend {
		return new EddSlBackend(
			$this->store_url(),
			self::ITEM_IDS,
			$this->option_key(),
			$this->plugin_name()
		);
	}

	/**
	 * EDD store base URL (filterable for staging environments).
	 */
	protected function store_url(): string {
		return apply_filters( 'app_bridge_wp_erp_store_url', self::STORE_URL );
	}

	/**
	 * Not used by the EDD SL backend.
	 */
	protected function appsero_hash_id(): string {
		return '';
	}

	protected function plugin_name(): string {
		return 'FlyHR Mobile App';
	}

	protected function plugin_file(): string {
		return APP_BRIDGE_FILE;
	}

	protected function option_key(): string {
		return 'wp_erp_app_license';
	}

	protected function license_page_url(): string {
		return admin_url( 'admin.php?page=app-bridge-wp-erp#license' );
	}

	protected function get_mobile_app_name(): string {
		return 'wp-erp-app';
	}
}
