<?php
/**
 * license-php/lib/Entitlements.php
 * Presensi License Entitlements & Plans Engine.
 * 100% Identical schema to Node.js license-server.js.
 */

class Entitlements {
    const PLANS = [
        'BASIC' => [
            // V2 Schema
            'attendance' => true,
            'reports' => true,
            'export' => false,
            'multi_user' => false,
            'api' => false,
            'advanced' => false,
            // V1 Compatibility
            'basic_attendance' => true,
            'qr_attendance_scan' => true,
            'export_advanced_rekap' => false,
            'bulk_qr_generator' => false,
            'cloud_sync_backup' => false,
            'custom_branding_white_label' => false,
            'unlimited_user_database' => false,
            'realtime_gps_geofencing' => true
        ],
        'PRO' => [
            // V2 Schema
            'attendance' => true,
            'reports' => true,
            'export' => true,
            'multi_user' => true,
            'api' => false,
            'advanced' => false,
            // V1 Compatibility
            'basic_attendance' => true,
            'qr_attendance_scan' => true,
            'export_advanced_rekap' => true,
            'bulk_qr_generator' => true,
            'cloud_sync_backup' => true,
            'custom_branding_white_label' => false,
            'unlimited_user_database' => true,
            'realtime_gps_geofencing' => true
        ],
        'ENTERPRISE' => [
            // V2 Schema
            'attendance' => true,
            'reports' => true,
            'export' => true,
            'multi_user' => true,
            'api' => true,
            'advanced' => true,
            // V1 Compatibility
            'basic_attendance' => true,
            'qr_attendance_scan' => true,
            'export_advanced_rekap' => true,
            'bulk_qr_generator' => true,
            'cloud_sync_backup' => true,
            'custom_branding_white_label' => true,
            'unlimited_user_database' => true,
            'realtime_gps_geofencing' => true
        ]
    ];

    public static function getPlanEntitlements($planName = 'PRO', $legacyType = 'Lifetime') {
        $norm = strtoupper(trim((string)$planName));
        if ($norm && isset(self::PLANS[$norm])) {
            return self::PLANS[$norm];
        }
        if ($legacyType === 'Trial' || $norm === 'BASIC') {
            return self::PLANS['BASIC'];
        }
        if ($legacyType === 'Enterprise' || $norm === 'ENTERPRISE') {
            return self::PLANS['ENTERPRISE'];
        }
        return self::PLANS['PRO'];
    }
}
