<?php

/**
 * The class that contains helper functions to use MessageFlow API
 *
 * @link       https://autoserve.io
 * @since      1.1.2.2
 *
 * @package    Messageflow
 * @subpackage Messageflow/includes
 */

/**
 * The class that contains helper functions to use MessageFlow API
 *
 * @since      1.1.2.2
 * @package    Messageflow
 * @subpackage Messageflow/includes
 * @author     Autoserve <support@autoserve.io>
 */
class Messageflow_Api {
	/**
	 * Check whether the logged in account is valid
	 *
	 * @since    1.1.2.2
	 */
	public function check_account_status( $user_id ) {
		try {
			$api_url = 'https://api.messageflow.co/auth/status/' . $user_id;

			$response = wp_remote_get( $api_url );

			if ( ! is_wp_error( $response ) ) {
				$response_body = json_decode( wp_remote_retrieve_body( $response ) );
			}

			$is_valid_account = $response_body->status == 'VALID';

			return $is_valid_account;
		} catch (Exception $e) {
			echo 'Error calling MessageFlow status API. Error message: ' . $e->getMessage();
			return false;
		}
	}
}
