/*
 * Copyright 2018 ThoughtWorks, Inc.
 *
 * Licensed 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 com.thoughtworks.go.api.util;

import com.google.gson.JsonObject;
import com.thoughtworks.go.config.CaseInsensitiveString;

import static java.lang.String.format;

public abstract class HaltApiMessages {

    public static String notFoundMessage() {
        return "Either the resource you requested was not found, or you are not authorized to perform this action.";
    }

    public static String forbiddenMessage() {
        return "You are not authorized to perform this action.";
    }

    public static String entityAlreadyExistsMessage(String entityType, Object existingName) {
        return String.format("Failed to add %s '%s'. Another %s with the same name already exists.", entityType, existingName, entityType);
    }

    public static String renameOfEntityIsNotSupportedMessage(String entityType) {
        return String.format("Renaming of %s is not supported by this API.", entityType);
    }

    public static String etagDoesNotMatch(String entityType, CaseInsensitiveString name) {
        return etagDoesNotMatch(entityType, name.toString());
    }

    public static String etagDoesNotMatch(String entityType, String name) {
        return String.format("Someone has modified the configuration for %s '%s'. Please update your copy of the config with the changes and try again.", entityType, name);
    }

    public static String rateLimitExceeded() {
        return "Rate Limit Exceeded.";
    }

    public static String errorWhileEncryptingMessage() {
        return "An error occurred while encrypting the value. Please check the logs for more details.";
    }

    public static String jsonContentTypeExpected() {
        return "You must specify a 'Content-Type' of 'application/json'";
    }

    public static String deprecatedConfirmHeaderMissing() {
        return "Missing required header 'Confirm' with value 'true'";
    }

    public static String confirmHeaderMissing() {
        return "Missing required header 'X-GoCD-Confirm' with value 'true'";
    }

    public static String propertyIsNotAJsonString(String property, JsonObject jsonObject) {
        return String.format("Could not read property '%s' as a String in json `%s` ", property, jsonObject);
    }

    public static String propertyIsNotAJsonObject(String property, JsonObject jsonObject) {
        return String.format("Could not read property '%s' as a JsonObject in json `%s`", property, jsonObject);
    }

    public static String propertyIsNotAJsonStringArray(String property, JsonObject jsonObject) {
        return String.format("Could not read property '%s' as a JsonArray containing string in `%s`", property, jsonObject);
    }

    public static String propertyIsNotAJsonArray(String property, JsonObject jsonObject) {
        return String.format("Could not read property '%s' as a JsonArray in json `%s`", property, jsonObject);
    }

    public static String propertyIsNotAJsonBoolean(String property, JsonObject jsonObject) {
        return String.format("Could not read property '%s' as a Boolean in json `%s` ", property, jsonObject);
    }

    public static String missingJsonProperty(String property, JsonObject jsonObject) {
        return format("Json `%s` does not contain property '%s'", jsonObject, property);
    }

    public static String missingRequestParameter(String paramName) {
        return format("Request is missing parameter `%s`", paramName);
    }
}

@@ -1197,39 +1197,32 @@
 %0A        return 
-String.
 format(%22Failed t
@@ -1419,39 +1419,32 @@
 %0A        return 
-String.
 format(%22Renaming
@@ -1745,39 +1745,32 @@
 %0A        return 
-String.
 format(%22Someone 
@@ -2676,39 +2676,32 @@
 %0A        return 
-String.
 format(%22Could no
@@ -2878,39 +2878,32 @@
 %0A        return 
-String.
 format(%22Could no
@@ -3088,39 +3088,32 @@
 %0A        return 
-String.
 format(%22Could no
@@ -3304,39 +3304,32 @@
 %0A        return 
-String.
 format(%22Could no
@@ -3517,23 +3517,16 @@
  return 
-String.
 format(%22

Optimize imports and cleanup