You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

128 lines
3.2 KiB

//
// ExchangeModel.swift
// GMERemittance
//
// Created by gme_2 on 21/08/2018.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
import ObjectMapper
class ExchangeRateModel: Mappable {
var country: String?
var countryCode: String?
var currency: String?
var countryId: String?
var availableServices: [PaymentServiceType]?
init() {}
required init?(map: Map) {
}
func mapping(map: Map) {
country <- map["country"]
countryCode <- map["countryCode"]
currency <- map["currency"]
countryId <- map["countryId"]
availableServices <- map["serviceAvailable"]
}
}
extension ExchangeRateModel: TablePresenterProtocol {
var cellTitle: String? {
return "\(country ?? "") (\(currency ?? ""))"
}
var cellImage: UIImage? {
return CountryEnum(rawValue: countryCode?.lowercased() ?? "")?.flag
}
}
class PaymentServiceType: Mappable {
var id: String?
var type: String?
var currency: [String]?
var subtitle: String?
init() {}
required init?(map: Map) {
}
func mapping(map: Map) {
id <- map["id"]
type <- map["text"]
currency <- map["currency"]
subtitle <- map["description"]
}
func toPaymentMethodModel() -> PaymentMethodModel {
return PaymentMethodModel(id: id, name: type, localizedName: subtitle)
}
}
extension PaymentServiceType: Equatable {
static func == (lhs: PaymentServiceType, rhs: PaymentServiceType) -> Bool {
return lhs.id == rhs.id &&
lhs.type == rhs.type &&
lhs.currency == rhs.currency &&
lhs.subtitle == rhs.subtitle
}
}
extension PaymentServiceType: TablePresenterProtocol {
var cellTitle: String? {
return "\(subtitle ?? "")"
}
var cellImage: UIImage? {
switch id ?? "1" {
case "1":
return UIImage(named: "cash_payment")?.tint(with: UIColor.themeText)
case "2":
return UIImage(named: "bank_deposit")?.tint(with: UIColor.themeText)
case "12":
return #imageLiteral(resourceName: "ic_homeDelivery")
case "13":
return UIImage(named: "jme_wallet")?.tint(with: UIColor.themeText)
case "14":
return #imageLiteral(resourceName: "ic_card_payment")
default: return nil
}
}
}
class ExchangeRateContainer: Mappable {
var errorCode: String?
var message: String?
var id: String?
var data: [ExchangeRateModel]?
required init?(map: Map) {
}
func mapping(map: Map) {
errorCode <- map["ErrorCode"]
id <- map["Id"]
message <- map["Msg"]
data <- map["Data"]
}
}
extension UIImage {
func tint(with color: UIColor) -> UIImage {
var image = withRenderingMode(.alwaysTemplate)
UIGraphicsBeginImageContextWithOptions(size, false, scale)
color.set()
image.draw(in: CGRect(origin: .zero, size: size))
image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}