//
// Generated by SwagGen
// https://github.com/yonaskolb/SwagGen
//

import Foundation

extension PetstoreTest.Pet {

    public enum UploadFile {

        public static let service = APIService<Response>(id: "uploadFile", tag: "pet", method: "POST", path: "/pet/{petId}/uploadImage", hasBody: true, authorization: Authorization(type: "petstore_auth", scope: "write:pets"))

        public final class Request: APIRequest<Response> {

            public struct Options {

                /** ID of pet to update */
                public var petId: Int

                /** Additional data to pass to server */
                public var additionalMetadata: String?

                /** file to upload */
                public var file: URL?

                public init(petId: Int, additionalMetadata: String? = nil, file: URL? = nil) {
                    self.petId = petId
                    self.additionalMetadata = additionalMetadata
                    self.file = file
                }
            }

            public var options: Options

            public init(options: Options) {
                self.options = options
                super.init(service: UploadFile.service)
            }

            /// convenience initialiser so an Option doesn't have to be created
            public convenience init(petId: Int, additionalMetadata: String? = nil, file: URL? = nil) {
                let options = Options(petId: petId, additionalMetadata: additionalMetadata, file: file)
                self.init(options: options)
            }

            public override var path: String {
                return super.path.replacingOccurrences(of: "{" + "petId" + "}", with: "\(self.options.petId)")
            }

            public override var parameters: [String: Any] {
                var params: [String: Any] = [:]
                if let additionalMetadata = options.additionalMetadata {
                  params["additionalMetadata"] = additionalMetadata
                }
                if let file = options.file?.encode() {
                  params["file"] = file
                }
                return params
            }
        }

        public enum Response: APIResponseValue, CustomStringConvertible, CustomDebugStringConvertible {
            public typealias SuccessType = ApiResponse

            /** successful operation */
            case status200(ApiResponse)

            public var success: ApiResponse? {
                switch self {
                case .status200(let response): return response
                }
            }

            public var response: Any {
                switch self {
                case .status200(let response): return response
                }
            }

            public var statusCode: Int {
                switch self {
                case .status200: return 200
                }
            }

            public var successful: Bool {
                switch self {
                case .status200: return true
                }
            }

            public init(statusCode: Int, data: Data) throws {
                let decoder = JSONDecoder()
                switch statusCode {
                case 200: self = try .status200(decoder.decode(ApiResponse.self, from: data))
                default: throw APIError.unexpectedStatusCode(statusCode: statusCode, data: data)
                }
            }

            public var description: String {
                return "\(statusCode) \(successful ? "success" : "failure")"
            }

            public var debugDescription: String {
                var string = description
                let responseString = "\(response)"
                if responseString != "()" {
                    string += "\n\(responseString)"
                }
                return string
            }
        }
    }
}
