<?php
function tm_12_check_license() {
    return [
        'status'  => true,
        'message' => "passed",
    ];
    if (!defined('LICENSE_URL')) {
        return [
            'status' => false,
            'message' => 'LICENSE_URL is not defined.',
        ];
    }

    $license = get_option('my_plugin_license_key');
    $domain = parse_url(home_url(), PHP_URL_HOST);

    $response = wp_remote_post(LICENSE_URL . "/api/license-keys/validate", [
        'method'  => 'POST',
        'timeout' => 15,
        'headers' => [
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
            'Referer'      => home_url(),
        ],
        'body'    => json_encode([
            'key'    => $license,
            'domain' => $domain,
        ]),
    ]);

    if (is_wp_error($response)) {
        return [
            'status'  => false,
            'message' => $response->get_error_message(),
        ];
    }

    $body = wp_remote_retrieve_body($response);
    $result = json_decode($body, true);

    if (empty($body) || !is_array($result)) {
        return [
            'status'  => false,
            'message' => 'Invalid response received from license server.',
        ];
    }

    if (!empty($result['license_info']['id'])) {
        return [
            'status'       => true,
            'license_info' => $result['license_info'],
            'message'      => $result['message'] ?? '',
        ];
    }

    return [
        'status'     => false,
        'error_code' => $result['error_code'] ?? 0,
        'message'    => $result['message'] ?? 'An unknown error occurred.',
    ];
}



