// Automatically generated by xdrgen
// DO NOT EDIT or your changes may be overwritten

import Foundation

// === xdr source ============================================================

//  //: Result of ManageSale operation application along with result code
//  union ManageSaleResult switch (ManageSaleResultCode code)
//  {
//  case SUCCESS:
//      ManageSaleResultSuccess success;
//  default:
//      void;
//  };

//  ===========================================================================
public enum ManageSaleResult: XDRDiscriminatedUnion {
  case success(ManageSaleResultSuccess)

  public var discriminant: Int32 {
    switch self {
    case .success: return ManageSaleResultCode.success.rawValue
    }
  }

  public func toXDR() -> Data {
    var xdr = Data()

    xdr.append(self.discriminant.toXDR())

    switch self {
    case .success(let data): xdr.append(data.toXDR())
    }

    return xdr
  }

  public init(xdrData: inout Data) throws {
    let discriminant = try Int32(xdrData: &xdrData)

    switch discriminant {
    case ManageSaleResultCode.success.rawValue:
      let data = try ManageSaleResultSuccess(xdrData: &xdrData)
      self = .success(data)
    default:
      throw XDRErrors.unknownEnumCase
    }
  }
}
