<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

class Falcify_Usage {
    const TRANSIENT = 'falcify_usage_cache';
    public static function init() {}
    public static function get( $force = false ) {
        if ( ! $force ) {
            $c = get_transient( self::TRANSIENT );
            if ( $c ) return $c;
        }
        $r = Falcify_Api::request( '/api/wordpress/usage', array(
            'api_key' => Falcify_Settings::get_value( 'api_key' ),
            'site_url' => home_url(),
        ), 'GET' );
        if ( $r['ok'] && ! empty( $r['data']['success'] ) ) {
            set_transient( self::TRANSIENT, $r['data'], 5 * MINUTE_IN_SECONDS );
            return $r['data'];
        }
        return null;
    }
}
