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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
5 years ago
  1. //
  2. // ExchangeModel.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 21/08/2018.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import ObjectMapper
  10. class ExchangeRateModel: Mappable {
  11. var country: String?
  12. var countryCode: String?
  13. var currency: String?
  14. var countryId: String?
  15. var availableServices: [PaymentServiceType]?
  16. init() {}
  17. required init?(map: Map) {
  18. }
  19. func mapping(map: Map) {
  20. country <- map["country"]
  21. countryCode <- map["countryCode"]
  22. currency <- map["currency"]
  23. countryId <- map["countryId"]
  24. availableServices <- map["serviceAvailable"]
  25. }
  26. }
  27. extension ExchangeRateModel: TablePresenterProtocol {
  28. var cellTitle: String? {
  29. return "\(country ?? "") (\(currency ?? ""))"
  30. }
  31. var cellImage: UIImage? {
  32. return CountryEnum(rawValue: countryCode?.lowercased() ?? "")?.flag
  33. }
  34. }
  35. class PaymentServiceType: Mappable {
  36. var id: String?
  37. var type: String?
  38. var currency: [String]?
  39. var subtitle: String?
  40. init() {}
  41. required init?(map: Map) {
  42. }
  43. func mapping(map: Map) {
  44. id <- map["id"]
  45. type <- map["text"]
  46. currency <- map["currency"]
  47. subtitle <- map["description"]
  48. }
  49. func toPaymentMethodModel() -> PaymentMethodModel {
  50. return PaymentMethodModel(id: id, name: type, localizedName: subtitle)
  51. }
  52. }
  53. extension PaymentServiceType: Equatable {
  54. static func == (lhs: PaymentServiceType, rhs: PaymentServiceType) -> Bool {
  55. return lhs.id == rhs.id &&
  56. lhs.type == rhs.type &&
  57. lhs.currency == rhs.currency &&
  58. lhs.subtitle == rhs.subtitle
  59. }
  60. }
  61. extension PaymentServiceType: TablePresenterProtocol {
  62. var cellTitle: String? {
  63. return "\(subtitle ?? "")"
  64. }
  65. var cellImage: UIImage? {
  66. switch id ?? "1" {
  67. case "1":
  68. return UIImage(named: "cash_payment")?.tint(with: UIColor.themeText)
  69. case "2":
  70. return UIImage(named: "bank_deposit")?.tint(with: UIColor.themeText)
  71. case "12":
  72. return #imageLiteral(resourceName: "ic_homeDelivery")
  73. case "13":
  74. return UIImage(named: "jme_wallet")?.tint(with: UIColor.themeText)
  75. case "14":
  76. return #imageLiteral(resourceName: "ic_card_payment")
  77. default: return nil
  78. }
  79. }
  80. }
  81. class ExchangeRateContainer: Mappable {
  82. var errorCode: String?
  83. var message: String?
  84. var id: String?
  85. var data: [ExchangeRateModel]?
  86. required init?(map: Map) {
  87. }
  88. func mapping(map: Map) {
  89. errorCode <- map["ErrorCode"]
  90. id <- map["Id"]
  91. message <- map["Msg"]
  92. data <- map["Data"]
  93. }
  94. }
  95. extension UIImage {
  96. func tint(with color: UIColor) -> UIImage {
  97. var image = withRenderingMode(.alwaysTemplate)
  98. UIGraphicsBeginImageContextWithOptions(size, false, scale)
  99. color.set()
  100. image.draw(in: CGRect(origin: .zero, size: size))
  101. image = UIGraphicsGetImageFromCurrentImageContext()!
  102. UIGraphicsEndImageContext()
  103. return image
  104. }
  105. }