//
// Generated by SwagGen with template `SwiftSAPURLSession`
// https://github.com/MarcoEidinger/SwagGen/tree/sap/Swift-SAPURLSession
//

import Foundation

extension ARService.File {

    /**
    update file data (reality, usdz or image) by id

    Update contents of a file
    */
    internal enum UpdateFileById {

        internal static let service = APIService<Response>(id: "updateFileById", tag: "file", method: "PUT", path: "/scene/{sceneId}/file/{fileId}", hasBody: true, isUpload: true)

        internal final class Request: APIRequest<Response> {

            internal struct Options {

                /** ID of scene */
                internal var sceneId: Int

                /** ID of file */
                internal var fileId: String

                /** File to be uploaded for scene */
                internal var file: File

                internal init(sceneId: Int, fileId: String, file: File) {
                    self.sceneId = sceneId
                    self.fileId = fileId
                    self.file = file
                }
            }

            internal var options: Options

            internal init(options: Options) {
                self.options = options
                super.init(service: UpdateFileById.service)
            }

            /// convenience initialiser so an Option doesn't have to be created
            internal convenience init(sceneId: Int, fileId: String, file: File) {
                let options = Options(sceneId: sceneId, fileId: fileId, file: file)
                self.init(options: options)
            }

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

            internal override var formParameters: [String: Any] {
                var params: [String: Any] = [:]
                params["file"] = options.file.encode()
                return params
            }
        }

        internal enum Response: APIResponseValue, CustomStringConvertible, CustomDebugStringConvertible {
            internal typealias SuccessType = String

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

            /** Required file is not uploaded, uploading file failed to pass virus scan */
            case status400

            /** Business user is not authenticated */
            case status401

            /** File not found */
            case status404

            /** Invalid request path or method */
            case status405

            /** Server internal error */
            case status500

            internal var success: String? {
                switch self {
                case .status200(let response): return response
                default: return nil
                }
            }

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

            internal var statusCode: Int {
                switch self {
                case .status200: return 200
                case .status400: return 400
                case .status401: return 401
                case .status404: return 404
                case .status405: return 405
                case .status500: return 500
                }
            }

            internal var successful: Bool {
                switch self {
                case .status200: return true
                case .status400: return false
                case .status401: return false
                case .status404: return false
                case .status405: return false
                case .status500: return false
                }
            }

            internal init(statusCode: Int, data: Data, decoder: ResponseDecoder) throws {
                switch statusCode {
                case 200: self = try .status200(decoder.decode(String.self, from: data))
                case 400: self = .status400
                case 401: self = .status401
                case 404: self = .status404
                case 405: self = .status405
                case 500: self = .status500
                default: throw APIClientError.unexpectedStatusCode(statusCode: statusCode, data: data)
                }
            }

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

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