package com.l7tech.external.assertions.gatewaygraphql.server.data;

import com.l7tech.common.http.HttpMethod;
import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.policy.PolicyVersion;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import lombok.Generated;

public abstract class PublishedServiceDTO extends EntityDTO<PublishedService> {
   protected PolicyVersion subEntity;
   private boolean a;
   private final AtomicReference<Object> b = new AtomicReference<>();
   private final AtomicReference<Object> c = new AtomicReference<>();

   protected PublishedServiceDTO(PublishedService var1) {
      super(var1);
   }

   @Override
   public String getGuid() {
      return this.entity.getPolicy().getGuid();
   }

   public String getResolutionPath() {
      return this.entity.getRoutingUri();
   }

   public String getFolderPath() {
      return this.entity.getFolder().getPath();
   }

   public boolean isEnabled() {
      return !this.entity.isDisabled();
   }

   public boolean isSoap() {
      return this.entity.isSoap();
   }

   public boolean isTracingEnabled() {
      return this.entity.isTracingEnabled();
   }

   public boolean isWssProcessingEnabled() {
      return this.entity.isWssProcessingEnabled();
   }

   @Override
   public Integer getVersion() {
      return this.entity.getVersion() + this.entity.getPolicy().getVersion();
   }

   public List<EntityProperty> getProperties() {
      List var1 = null;
      if (this.entity.getProperties() != null) {
         var1 = this.entity
            .getProperties()
            .entrySet()
            .stream()
            .map(var0 -> new EntityProperty((String)var0.getKey(), (String)var0.getValue()))
            .collect(Collectors.toList());
         if (var1.isEmpty()) {
            var1 = null;
         }
      }

      return var1;
   }

   public boolean isPolicyVersionSelected() {
      return this.a;
   }

   public PolicyVersion getPolicyVersion() {
      return this.subEntity;
   }

   public void setPolicyVersion(PolicyVersion var1) {
      this.setPolicyVersion(var1, true);
   }

   public void setPolicyVersion(PolicyVersion var1, boolean var2) {
      this.subEntity = var1;
      this.a = var2;
   }

   protected PolicyDTO loadPolicy() {
      return new PolicyDTO(this.entity.getPolicy(), this.subEntity);
   }

   protected List<HttpMethod> loadMethodsAllowed() {
      return new ArrayList<>(this.entity.getHttpMethodsReadOnly());
   }

   @Generated
   public PolicyDTO getPolicy() {
      Object var1 = this.b.get();
      if (var1 == null) {
         synchronized (this.b) {
            var1 = this.b.get();
            if (var1 == null) {
               PolicyDTO var3 = this.loadPolicy();
               var1 = var3 == null ? this.b : var3;
               this.b.set(var1);
            }
         }
      }

      return (PolicyDTO)(var1 == this.b ? null : var1);
   }

   @Generated
   public List<HttpMethod> getMethodsAllowed() {
      Object var1 = this.c.get();
      if (var1 == null) {
         synchronized (this.c) {
            var1 = this.c.get();
            if (var1 == null) {
               List var3 = this.loadMethodsAllowed();
               var1 = var3 == null ? this.c : var3;
               this.c.set(var1);
            }
         }
      }

      return (List<HttpMethod>)(var1 == this.c ? null : var1);
   }
}
