<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;
use QuadLayers\IGG\Services\Cache;

/**
 * Api_Rest_Accounts_Delete Class
 */
class Delete extends Base {

	protected static $route_path = 'accounts';

	protected $cache_engine;

	public function callback( \WP_REST_Request $request ) {

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

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

			if ( ! $response ) {
				throw new \Exception( sprintf( esc_html__( 'Can\'t delete account, account_id not found.', 'insta-gallery' ), $account_id ), 412 );
			}

			// Clear cache

			$cache_key = "profile_{$account_id}";

			$cache_engine = new Cache( 6, true, $cache_key );

			$cache_engine->delete_key( $cache_key );

			return $this->handle_response( $response );

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