//===----------------------------------------------------------------------===//
//
// This source file is part of the AWSSDKSwift open source project
//
// Copyright (c) 2017-2020 the AWSSDKSwift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of AWSSDKSwift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/swift-aws/aws-sdk-swift/blob/main/CodeGenerator/Sources/CodeGenerator/main.swift. DO NOT EDIT.

import AWSSDKSwiftCore

/// Error enum for AutoScaling
public enum AutoScalingErrorType: AWSErrorType {
    case activeInstanceRefreshNotFoundFault(message: String?)
    case alreadyExistsFault(message: String?)
    case instanceRefreshInProgressFault(message: String?)
    case invalidNextToken(message: String?)
    case limitExceededFault(message: String?)
    case resourceContentionFault(message: String?)
    case resourceInUseFault(message: String?)
    case scalingActivityInProgressFault(message: String?)
    case serviceLinkedRoleFailure(message: String?)
}

extension AutoScalingErrorType {
    public init?(errorCode: String, message: String?) {
        var errorCode = errorCode
        if let index = errorCode.firstIndex(of: "#") {
            errorCode = String(errorCode[errorCode.index(index, offsetBy: 1)...])
        }
        switch errorCode {
        case "ActiveInstanceRefreshNotFound":
            self = .activeInstanceRefreshNotFoundFault(message: message)
        case "AlreadyExists":
            self = .alreadyExistsFault(message: message)
        case "InstanceRefreshInProgress":
            self = .instanceRefreshInProgressFault(message: message)
        case "InvalidNextToken":
            self = .invalidNextToken(message: message)
        case "LimitExceeded":
            self = .limitExceededFault(message: message)
        case "ResourceContention":
            self = .resourceContentionFault(message: message)
        case "ResourceInUse":
            self = .resourceInUseFault(message: message)
        case "ScalingActivityInProgress":
            self = .scalingActivityInProgressFault(message: message)
        case "ServiceLinkedRoleFailure":
            self = .serviceLinkedRoleFailure(message: message)
        default:
            return nil
        }
    }
}

extension AutoScalingErrorType: CustomStringConvertible {
    public var description: String {
        switch self {
        case .activeInstanceRefreshNotFoundFault(let message):
            return "ActiveInstanceRefreshNotFound: \(message ?? "")"
        case .alreadyExistsFault(let message):
            return "AlreadyExists: \(message ?? "")"
        case .instanceRefreshInProgressFault(let message):
            return "InstanceRefreshInProgress: \(message ?? "")"
        case .invalidNextToken(let message):
            return "InvalidNextToken: \(message ?? "")"
        case .limitExceededFault(let message):
            return "LimitExceeded: \(message ?? "")"
        case .resourceContentionFault(let message):
            return "ResourceContention: \(message ?? "")"
        case .resourceInUseFault(let message):
            return "ResourceInUse: \(message ?? "")"
        case .scalingActivityInProgressFault(let message):
            return "ScalingActivityInProgress: \(message ?? "")"
        case .serviceLinkedRoleFailure(let message):
            return "ServiceLinkedRoleFailure: \(message ?? "")"
        }
    }
}
