jsdw_ios/QuickLocation/Model/MailboxModel.swift

101 lines
2.3 KiB
Swift

//
// MailboxModel.swift
// QuickLocation
//
import Foundation
import ObjectMapper
enum MailboxCategory: Int, CaseIterable {
case system = 1
case notice = 2
case interaction = 3
static let displayOrder: [MailboxCategory] = [.interaction, .notice, .system]
var title: String {
switch self {
case .interaction:
return "互动"
case .notice:
return "通知"
case .system:
return "系统"
}
}
var detailTitle: String { "\(title)消息" }
}
struct MailboxMessage: Mappable, Equatable {
var id = 0
var title = ""
var content = ""
var isRead = false
var type = MailboxCategory.system.rawValue
var senderId = ""
var senderIcon = ""
var modifyTime = ""
var category: MailboxCategory {
MailboxCategory(rawValue: type) ?? .system
}
init?(map: Map) {}
mutating func mapping(map: Map) {
id <- (map["id"], kStrTransformInt)
title <- (map["title"], kFlexString)
content <- (map["content"], kFlexString)
isRead <- map["is_read"]
type <- (map["type"], kStrTransformInt)
senderId <- (map["sender_id"], kFlexString)
senderIcon <- (map["sender_icon"], kFlexString)
modifyTime <- (map["mtime"], kFlexString)
}
}
struct MailboxListData: Mappable {
var page = 1
var size = 10
var total = 0
var messages: [MailboxMessage] = []
init?(map: Map) {}
mutating func mapping(map: Map) {
page <- (map["page"], kStrTransformInt)
size <- (map["size"], kStrTransformInt)
total <- (map["total"], kStrTransformInt)
messages <- map["datas"]
}
}
struct MailboxListResponse: BaseModelProtocol {
var code: String?
var message: String?
var data: MailboxListData?
init?(map: Map) {}
mutating func mapping(map: Map) {
code <- (map["code"], kIntTransformStr)
message <- map["message"]
data <- map["data"]
}
}
struct MailboxDetailResponse: BaseModelProtocol {
var code: String?
var message: String?
var data: MailboxMessage?
init?(map: Map) {}
mutating func mapping(map: Map) {
code <- (map["code"], kIntTransformStr)
message <- map["message"]
data <- map["data"]
}
}