package nxm.webvnc.lib;

import nxm.sys.net.HPage;

/**
 * Handles REST requests to close VNC sessions
 *
 * @author adw
 * @since NeXtMidas 4.1.1
 *
 */
public class CloseInstanceHandler implements RequestHandlerInterface {
  private VNCSessionManager sessionManager;

  /** Constructor
   *  @param sessionManager The {@link VNCSessionManager} to use
   */
  public CloseInstanceHandler (VNCSessionManager sessionManager) {
    this.sessionManager = sessionManager;
  }

  /** Handle the REST request.
   *
   *  @param uri  The URI used to access this resource.
   *  @param hp   The {@link HPage} representing the request.
   *  @return The data to be returned to the client.
   */
  @Override
  public String handleRequest (String uri, HPage hp) {
    if (hp.getParameters().containsKey("ID")) {
      sessionManager.closeVNCSession(hp.getParameters().getL("ID"));
      return "OK";
    }
    return "NOT FOUND";
  }
}
