//===----------------------------------------------------------------------===//
//
// 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 QLDBSession
public enum QLDBSessionErrorType: AWSErrorType {
    case badRequestException(message: String?)
    case invalidSessionException(message: String?)
    case limitExceededException(message: String?)
    case occConflictException(message: String?)
    case rateExceededException(message: String?)
}

extension QLDBSessionErrorType {
    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 "BadRequestException":
            self = .badRequestException(message: message)
        case "InvalidSessionException":
            self = .invalidSessionException(message: message)
        case "LimitExceededException":
            self = .limitExceededException(message: message)
        case "OccConflictException":
            self = .occConflictException(message: message)
        case "RateExceededException":
            self = .rateExceededException(message: message)
        default:
            return nil
        }
    }
}

extension QLDBSessionErrorType: CustomStringConvertible {
    public var description: String {
        switch self {
        case .badRequestException(let message):
            return "BadRequestException: \(message ?? "")"
        case .invalidSessionException(let message):
            return "InvalidSessionException: \(message ?? "")"
        case .limitExceededException(let message):
            return "LimitExceededException: \(message ?? "")"
        case .occConflictException(let message):
            return "OccConflictException: \(message ?? "")"
        case .rateExceededException(let message):
            return "RateExceededException: \(message ?? "")"
        }
    }
}
