/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.2-dev * User agent: apibuilder app.apibuilder.io/mard/mard2p-api/0.0.2-dev/http4s_0_23 */ package payp.mard2p.api.v0.models { package object json { import io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ import io.apibuilder.common.v0.models.json._ import io.apibuilder.generator.v0.models.json._ import io.apibuilder.spec.v0.models.json._ import payp.mard2p.api.v0.models.json._ // Make Scala 2.11 Either monadic private[v0] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v0] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v0] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v0] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v0] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v0] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v0] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderMard2pAPIAppSortBy: Decoder[payp.mard2p.api.v0.models.AppSortBy] = Decoder.decodeString.map(payp.mard2p.api.v0.models.AppSortBy(_)) implicit val jsonEncoderMard2pAPIAppSortBy: Encoder[payp.mard2p.api.v0.models.AppSortBy] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.AppSortBy](_.toString) implicit val jsonDecoderMard2pAPIOriginalType: Decoder[payp.mard2p.api.v0.models.OriginalType] = Decoder.decodeString.map(payp.mard2p.api.v0.models.OriginalType(_)) implicit val jsonEncoderMard2pAPIOriginalType: Encoder[payp.mard2p.api.v0.models.OriginalType] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.OriginalType](_.toString) implicit val jsonDecoderMard2pAPIPublication: Decoder[payp.mard2p.api.v0.models.Publication] = Decoder.decodeString.map(payp.mard2p.api.v0.models.Publication(_)) implicit val jsonEncoderMard2pAPIPublication: Encoder[payp.mard2p.api.v0.models.Publication] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.Publication](_.toString) implicit val jsonDecoderMard2pAPISortOrder: Decoder[payp.mard2p.api.v0.models.SortOrder] = Decoder.decodeString.map(payp.mard2p.api.v0.models.SortOrder(_)) implicit val jsonEncoderMard2pAPISortOrder: Encoder[payp.mard2p.api.v0.models.SortOrder] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.SortOrder](_.toString) implicit val jsonDecoderMard2pAPIVisibility: Decoder[payp.mard2p.api.v0.models.Visibility] = Decoder.decodeString.map(payp.mard2p.api.v0.models.Visibility(_)) implicit val jsonEncoderMard2pAPIVisibility: Encoder[payp.mard2p.api.v0.models.Visibility] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.Visibility](_.toString) implicit def decodeMard2pAPIAccount: Decoder[Account] = Decoder.instance { c => for { accountid <- c.downField("accountid").as[Long] ownerid <- c.downField("ownerid").as[String] totalAmount <- c.downField("total_amount").as[Double] currency <- c.downField("currency").as[String] sold <- c.downField("sold").as[Double] debit <- c.downField("debit").as[Double] } yield { Account( accountid = accountid, ownerid = ownerid, totalAmount = totalAmount, currency = currency, sold = sold, debit = debit ) } } implicit def encodeMard2pAPIAccount: Encoder[Account] = Encoder.instance { t => Json.fromFields(Seq( Some("accountid" -> t.accountid.asJson), Some("ownerid" -> t.ownerid.asJson), Some("total_amount" -> t.totalAmount.asJson), Some("currency" -> t.currency.asJson), Some("sold" -> t.sold.asJson), Some("debit" -> t.debit.asJson) ).flatten) } implicit def decodeMard2pAPIAccountForm: Decoder[AccountForm] = Decoder.instance { c => for { accountid <- c.downField("accountid").as[Long] ownerid <- c.downField("ownerid").as[String] totalAmount <- c.downField("total_amount").as[Option[Double]] sold <- c.downField("sold").as[Double] debit <- c.downField("debit").as[Option[Double]] currency <- c.downField("currency").as[String] } yield { AccountForm( accountid = accountid, ownerid = ownerid, totalAmount = totalAmount, sold = sold, debit = debit, currency = currency ) } } implicit def encodeMard2pAPIAccountForm: Encoder[AccountForm] = Encoder.instance { t => Json.fromFields(Seq( Some("accountid" -> t.accountid.asJson), Some("ownerid" -> t.ownerid.asJson), t.totalAmount.map(t => "total_amount" -> t.asJson), Some("sold" -> t.sold.asJson), t.debit.map(t => "debit" -> t.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPIDeposit: Decoder[Deposit] = Decoder.instance { c => for { depid <- c.downField("depid").as[Long] paymentid <- c.downField("paymentid").as[Long] } yield { Deposit( depid = depid, paymentid = paymentid ) } } implicit def encodeMard2pAPIDeposit: Encoder[Deposit] = Encoder.instance { t => Json.fromFields(Seq( Some("depid" -> t.depid.asJson), Some("paymentid" -> t.paymentid.asJson) ).flatten) } implicit def decodeMard2pAPIPayment: Decoder[Payment] = Decoder.instance { c => for { payid <- c.downField("payid").as[Long] actorid <- c.downField("actorid").as[String] amount <- c.downField("amount").as[Double] refAccountid <- c.downField("ref_accountid").as[Long] paymentMethod <- c.downField("payment_method").as[String] operatorid <- c.downField("operatorid").as[String] phone <- c.downField("phone").as[Long] pin <- c.downField("pin").as[Int] currency <- c.downField("currency").as[String] paymentContext <- c.downField("payment_context").as[String] } yield { Payment( payid = payid, actorid = actorid, amount = amount, refAccountid = refAccountid, paymentMethod = paymentMethod, operatorid = operatorid, phone = phone, pin = pin, currency = currency, paymentContext = paymentContext ) } } implicit def encodeMard2pAPIPayment: Encoder[Payment] = Encoder.instance { t => Json.fromFields(Seq( Some("payid" -> t.payid.asJson), Some("actorid" -> t.actorid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid" -> t.refAccountid.asJson), Some("payment_method" -> t.paymentMethod.asJson), Some("operatorid" -> t.operatorid.asJson), Some("phone" -> t.phone.asJson), Some("pin" -> t.pin.asJson), Some("currency" -> t.currency.asJson), Some("payment_context" -> t.paymentContext.asJson) ).flatten) } implicit def decodeMard2pAPIPaymentForm: Decoder[PaymentForm] = Decoder.instance { c => for { payid <- c.downField("payid").as[Long] actorid <- c.downField("actorid").as[String] amount <- c.downField("amount").as[Double] refAccountid <- c.downField("ref_accountid").as[Long] paymentMethod <- c.downField("payment_method").as[String] operatorid <- c.downField("operatorid").as[String] phone <- c.downField("phone").as[Long] pin <- c.downField("pin").as[Int] currency <- c.downField("currency").as[String] paymentContext <- c.downField("payment_context").as[String] } yield { PaymentForm( payid = payid, actorid = actorid, amount = amount, refAccountid = refAccountid, paymentMethod = paymentMethod, operatorid = operatorid, phone = phone, pin = pin, currency = currency, paymentContext = paymentContext ) } } implicit def encodeMard2pAPIPaymentForm: Encoder[PaymentForm] = Encoder.instance { t => Json.fromFields(Seq( Some("payid" -> t.payid.asJson), Some("actorid" -> t.actorid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid" -> t.refAccountid.asJson), Some("payment_method" -> t.paymentMethod.asJson), Some("operatorid" -> t.operatorid.asJson), Some("phone" -> t.phone.asJson), Some("pin" -> t.pin.asJson), Some("currency" -> t.currency.asJson), Some("payment_context" -> t.paymentContext.asJson) ).flatten) } implicit def decodeMard2pAPITransfer: Decoder[Transfer] = Decoder.instance { c => for { transferid <- c.downField("transferid").as[Long] senderid <- c.downField("senderid").as[String] amount <- c.downField("amount").as[Double] refAccountidReceiver <- c.downField("ref_accountid_receiver").as[Long] refAccountidSender <- c.downField("ref_accountid_sender").as[Long] currency <- c.downField("currency").as[String] } yield { Transfer( transferid = transferid, senderid = senderid, amount = amount, refAccountidReceiver = refAccountidReceiver, refAccountidSender = refAccountidSender, currency = currency ) } } implicit def encodeMard2pAPITransfer: Encoder[Transfer] = Encoder.instance { t => Json.fromFields(Seq( Some("transferid" -> t.transferid.asJson), Some("senderid" -> t.senderid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid_receiver" -> t.refAccountidReceiver.asJson), Some("ref_accountid_sender" -> t.refAccountidSender.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPITransferForm: Decoder[TransferForm] = Decoder.instance { c => for { transferid <- c.downField("transferid").as[Long] senderid <- c.downField("senderid").as[String] amount <- c.downField("amount").as[Double] refAccountidReceiver <- c.downField("ref_accountid_receiver").as[Long] refAccountidSender <- c.downField("ref_accountid_sender").as[Long] currency <- c.downField("currency").as[String] } yield { TransferForm( transferid = transferid, senderid = senderid, amount = amount, refAccountidReceiver = refAccountidReceiver, refAccountidSender = refAccountidSender, currency = currency ) } } implicit def encodeMard2pAPITransferForm: Encoder[TransferForm] = Encoder.instance { t => Json.fromFields(Seq( Some("transferid" -> t.transferid.asJson), Some("senderid" -> t.senderid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid_receiver" -> t.refAccountidReceiver.asJson), Some("ref_accountid_sender" -> t.refAccountidSender.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPIValidation: Decoder[Validation] = Decoder.instance { c => for { valid <- c.downField("valid").as[Boolean] errors <- c.downField("errors").as[Seq[String]] } yield { Validation( valid = valid, errors = errors ) } } implicit def encodeMard2pAPIValidation: Encoder[Validation] = Encoder.instance { t => Json.fromFields(Seq( Some("valid" -> t.valid.asJson), Some("errors" -> t.errors.asJson) ).flatten) } implicit def decodeMard2pAPIWithdraw: Decoder[Withdraw] = Decoder.instance { c => for { wdwid <- c.downField("wdwid").as[Long] paymentid <- c.downField("paymentid").as[Long] } yield { Withdraw( wdwid = wdwid, paymentid = paymentid ) } } implicit def encodeMard2pAPIWithdraw: Encoder[Withdraw] = Encoder.instance { t => Json.fromFields(Seq( Some("wdwid" -> t.wdwid.asJson), Some("paymentid" -> t.paymentid.asJson) ).flatten) } } }