/*
 * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.carbon.apimgt.api.model;

public class ApiTypeWrapper {
    private API api;
    private APIProduct apiProduct;
    private boolean isAPIProduct;

    public ApiTypeWrapper(API api) {
        this.api = api;
        isAPIProduct = false;
    }

    public ApiTypeWrapper(APIProduct apiProduct) {
        this.apiProduct = apiProduct;
        isAPIProduct = true;
    }

    public boolean isAPIProduct() {
        return isAPIProduct;
    }

    public API getApi() {
        return api;
    }

    public APIProduct getApiProduct() {
        return apiProduct;
    }

    public String getName() {
        if (isAPIProduct) {
            return apiProduct.getId().getName();
        } else {
            return api.getId().getName();
        }
    }

    public String getStatus() {
        if (isAPIProduct) {
            return apiProduct.getState();
        } else {
            return api.getStatus();
        }
    }

    public void setTier(String tier) {
        if (isAPIProduct) {
            apiProduct.getId().setTier(tier);
        } else {
            api.getId().setTier(tier);
        }
    }

    public void setContext(String context) {
        if (isAPIProduct) {
            apiProduct.setContext(context);
        } else {
            api.setContext(context);
        }
    }

    public String getContext() {
        if (isAPIProduct) {
            return apiProduct.getContext();
        } else {
            return api.getContext();
        }
    }

    public void setContextTemplate(String contextTemplate) {
        if (isAPIProduct) {
            apiProduct.setContextTemplate(contextTemplate);
        } else {
            api.setContextTemplate(contextTemplate);
        }
    }

    public String getContextTemplate() {
        if (isAPIProduct) {
            return apiProduct.getContextTemplate();
        } else {
            return api.getContextTemplate();
        }
    }

    public Identifier getId() {
        if (isAPIProduct) {
            return apiProduct.getId();
        } else {
            return api.getId();
        }
    }

    public void setThumbnailUrl(String thumbnailUrl) {
        if (isAPIProduct) {
            apiProduct.setThumbnailUrl(thumbnailUrl);
        } else {
            api.setThumbnailUrl(thumbnailUrl);
        }
    }

    public String getVisibleRoles() {
        if (isAPIProduct) {
            return apiProduct.getVisibleRoles();
        } else {
            return api.getVisibleRoles();
        }
    }

    public String getVisibility() {
        if (isAPIProduct) {
            return apiProduct.getVisibility();
        } else {
            return api.getVisibility();
        }
    }
}

@@ -1281,36 +1281,39 @@
 ame() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -1308,38 +1308,18 @@
 IProduct
-) %7B%0A            return
+ ?
  apiProd
@@ -1343,45 +1343,10 @@
 me()
-;%0A        %7D else %7B%0A            return
+ :
  api
@@ -1361,34 +1361,24 @@
 .getName();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -1404,36 +1404,39 @@
 tus() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -1435,89 +1435,34 @@
 duct
-) %7B%0A            return apiProduct.getState();%0A        %7D else %7B%0A            return
+ ? apiProduct.getState() :
  api
@@ -1471,34 +1471,24 @@
 etStatus();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -1889,36 +1889,39 @@
 ext() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -1916,38 +1916,18 @@
 IProduct
-) %7B%0A            return
+ ?
  apiProd
@@ -1946,45 +1946,10 @@
 xt()
-;%0A        %7D else %7B%0A            return
+ :
  api
@@ -1959,34 +1959,24 @@
 tContext();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -2247,36 +2247,39 @@
 ate() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -2274,38 +2274,18 @@
 IProduct
-) %7B%0A            return
+ ?
  apiProd
@@ -2312,45 +2312,10 @@
 te()
-;%0A        %7D else %7B%0A            return
+ :
  api
@@ -2333,34 +2333,24 @@
 Template();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -2376,36 +2376,39 @@
 tId() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -2407,86 +2407,31 @@
 duct
-) %7B%0A            return apiProduct.getId();%0A        %7D else %7B%0A            return
+ ? apiProduct.getId() :
  api
@@ -2436,34 +2436,24 @@
 pi.getId();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -2703,36 +2703,39 @@
 les() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -2730,38 +2730,18 @@
 IProduct
-) %7B%0A            return
+ ?
  apiProd
@@ -2765,45 +2765,10 @@
 es()
-;%0A        %7D else %7B%0A            return
+ :
  api
@@ -2783,34 +2783,24 @@
 bleRoles();%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -2830,36 +2830,39 @@
 ity() %7B%0A        
-if (
+return 
 isAPIProduct) %7B%0A
@@ -2861,30 +2861,10 @@
 duct
-) %7B%0A            return
+ ?
  api
@@ -2890,45 +2890,10 @@
 ty()
-;%0A        %7D else %7B%0A            return
+ :
  api
@@ -2910,26 +2910,16 @@
 lity();%0A
-        %7D%0A
     %7D%0A%7D%0A

Modify if-else into ternary operator in ApiTypeWrapper