<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php
namespace QuadLayers\IGG\Api\Rest\Endpoints\Backend\Accounts;

use QuadLayers\IGG\Api\Rest\Endpoints\Backend\Base;
use QuadLayers\IGG\Models\Accounts as Models_Accounts;

/**
 * Api_Rest_Accounts_Get Class
 */
class Get extends Base {

	protected static $route_path = 'accounts';

	public function callback( \WP_REST_Request $request ) {

		try {

			$account_id = $request->get_param( 'id' ) ? trim( $request->get_param( 'id' ) ) : '';

			if ( ! $account_id ) {

				$response = Models_Accounts::instance()->get_all() ?? array();

				return $this->handle_response( $response );
			}

			$response = Models_Accounts::instance()->get( $account_id );

			if ( ! $response ) {
				throw new \Exception( sprintf( esc_html__( 'Account %s not found.', 'insta-gallery' ), $account_id ), 412 );
			}

			return $this->handle_response( $response );

		} catch ( \Exception $e ) {
			$response = array(
				'code'    => $e->getCode(),
				'message' =>