/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import Foundation


public protocol TSerializable {

  /// TType for instance
  static var thriftType: TType { get }

  /// Read TSerializable instance from Protocol
  static func read(from proto: TProtocol) throws -> Self

  /// Write TSerializable instance to Protocol
  func write(to proto: TProtocol) throws

}

extension TSerializable {
  public static func write(_ value: Self, to proto: TProtocol) throws {
    try value.write(to: proto)
  }

  /// convenience for member access
  public var thriftType: TType { return Self.thriftType }
}

/// Default read/write for primitave Thrift types:
/// Bool, Int8 (byte), Int16, Int32, Int64, Double, String

extension Bool : TSerializable {
  public static var thriftType: TType { return .bool }

  public static func read(from proto: TProtocol) throws -> Bool {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}

extension Int8 : TSerializable {
  public static var thriftType: TType { return .i8 }

  public static func read(from proto: TProtocol) throws -> Int8 {
    return try proto.read() as Int8
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(Int8(self))
  }
}

extension Int16 : TSerializable {
  public static var thriftType: TType { return .i16 }

  public static func read(from proto: TProtocol) throws -> Int16 {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}

extension Int32 : TSerializable {
  public static var thriftType: TType { return .i32 }

  public static func read(from proto: TProtocol) throws -> Int32 {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}


extension Int64 : TSerializable {
  public static var thriftType: TType { return .i64 }

  public static func read(from proto: TProtocol) throws -> Int64 {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}

extension Double : TSerializable {
  public static var thriftType: TType { return .double }

  public static func read(from proto: TProtocol) throws -> Double {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}

extension String : TSerializable {
  public static var thriftType: TType { return .string }

  public static func read(from proto: TProtocol) throws -> String {
    return try proto.read()
  }

  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}

extension UUID : TSerializable {
  public static var thriftType: TType { .uuid }
  
  public static func read(from proto: TProtocol) throws -> UUID {
    return try proto.read()
  }
  
  public func write(to proto: TProtocol) throws {
    try proto.write(self)
  }
}
