<?php
namespace ComptaFlowPro\Services;

defined('ABSPATH') || exit;

/**
 * Plan Manager - Lite Version
 * 
 * This is the free version of ComptaFlow.
 * All features return "LITE" plan with no restrictions.
 * For advanced features (FEC export, VAT management, Bank reconciliation, etc.),
 * upgrade to ComptaFlow Pro at https://comptaflow.meetempo.com
 */
class PlanManager
{
    /**
     * Get current plan (always LITE in free version)
     */
    public static function getCurrentPlan(): string
    {
        return 'LITE';
    }

    /**
     * Get transaction limit (unlimited in LITE)
     */
    public static function getTransactionLimit(): ?int
    {
        return null; // Unlimited
    }

    /**
     * Check if a feature is available (PRO features return false)
     */
    public static function hasFeature(string $feature): bool
    {
        // LITE version features (always available)
        $lite_features = [
            'basic_accounting',
            'export_csv',
            'export_balance',
            'export_journal',
            'export_grandlivre',
            'export_resultat'
        ];
        
        return in_array($feature, $lite_features);
    }

    /**
     * Check if can add transaction (always true - no limits)
     */
    public static function canAddTransaction(): bool
    {
        return true;
    }

    /**
     * Get monthly transaction count
     */
    public static function getMonthlyTransactionCount(): int
    {
        global $wpdb;
        $table = $wpdb->prefix . 'cfp_transactions';
        $user_id = get_current_user_id();
        
        $start_of_month = gmdate('Y-m-01');
        $end_of_month = gmdate('Y-m-t');
        
        $count = $wpdb->get_var($wpdb->prepare(
            "SELECT COUNT(*) FROM {$table} 
             WHERE created_by = %d 
             AND date_txn BETWEEN %s AND %s",
            $user_id, $start_of_month, $end_of_month
        ));
        
        return (int)$count;
    }

    /**
     * Get current price (always 0 for LITE)
     */
    public static function getCurrentPrice(): float
    {
        return 0.0;
    }
}
