package com.xjeffrose.xio.http;

import com.typesafe.config.ConfigFactory;
import java.util.function.Function;
import lombok.Getter;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
@Getter
public class RouteState {
  private final Route route;
  private final PipelineRequestHandler handler;

  public final String path;
  public final String permissionNeeded;

  public static Route buildRoute(RouteConfig config) {
    return Route.build(config.path());
  }

  public RouteState(
      Function<RouteConfig, Route> factory, RouteConfig config, PipelineRequestHandler handler) {
    this.route = factory.apply(config);
    this.path = config.path();
    this.permissionNeeded = config.permissionNeeded();
    this.handler = handler;
  }

  public RouteState(RouteConfig config, PipelineRequestHandler handler) {
    this(RouteState::buildRoute, config, handler);
  }

  public RouteState(
      String path, Route route, String permissionNeeded, PipelineRequestHandler handler) {
    this.path = path;
    this.route = route;
    this.permissionNeeded = permissionNeeded;
    this.handler = handler;
  }

  public static RouteState defaultRoute(PipelineRequestHandler handler) {
    RouteConfig config = new RouteConfig(ConfigFactory.load().getConfig("xio.defaultRoute"));
    return new RouteState((ignored) -> Route.build("*"), config, handler);
  }

  public boolean matches(String path) {
    return route.matches(path);
  }
}

@@ -334,48 +334,8 @@
 ath;
-%0A  public final String permissionNeeded;
 %0A%0A  
@@ -625,63 +625,8 @@
 ();%0A
-    this.permissionNeeded = config.permissionNeeded();%0A
     
@@ -804,23 +804,16 @@
 teState(
-%0A      
 String p
@@ -833,33 +833,8 @@
 ute,
- String permissionNeeded,
  Pip
@@ -914,54 +914,8 @@
 te;%0A
-    this.permissionNeeded = permissionNeeded;%0A
     

Revert "br/TACO-236: added permission needed string to route object"