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

import Foundation

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

//  //: Result of successful application of `CreateAccount` operation
//  struct CreateAccountSuccess
//  {
//      //: Unique unsigned integer identifier of the new account
//      uint64 sequentialID;
//  
//      //: reserved for future use
//      union switch (LedgerVersion v)
//      {
//      case EMPTY_VERSION:
//          void;
//      }
//      ext;
//  };

//  ===========================================================================
public struct CreateAccountSuccess: XDRCodable {
  public var sequentialID: Uint64
  public var ext: CreateAccountSuccessExt

  public init(
      sequentialID: Uint64,
      ext: CreateAccountSuccessExt) {

    self.sequentialID = sequentialID
    self.ext = ext
  }

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

    xdr.append(self.sequentialID.toXDR())
    xdr.append(self.ext.toXDR())

    return xdr
  }

  public init(xdrData: inout Data) throws {
    self.sequentialID = try Uint64(xdrData: &xdrData)
    self.ext = try CreateAccountSuccessExt(xdrData: &xdrData)
  }

  public enum CreateAccountSuccessExt: XDRDiscriminatedUnion {
    case emptyVersion

    public var discriminant: Int32 {
      switch self {
      case .emptyVersion: return LedgerVersion.emptyVersion.rawValue
      }
    }

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

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

      switch self {
      case .emptyVersion: xdr.append(Data())
      }

      return xdr
    }

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

      switch discriminant {
      case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion
      default:
        throw XDRErrors.unknownEnumCase
      }
    }

  }
}
