Files
suixinkan_uikit/suixinkan/Features/Task/Models/TaskModels.swift

181 lines
4.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// TaskModels.swift
// suixinkan
//
import Foundation
/// Android `AddTaskRequest`
struct AddTaskRequest: Encodable, Sendable, Equatable {
let scenicId: Int
let name: String
let orderNumber: String?
let remark: String
let urgentHour: Int
let cloudFile: [TaskCloudFileItem]
let uploadFile: [TaskUploadFileItem]
enum CodingKeys: String, CodingKey {
case scenicId = "scenic_id"
case name
case orderNumber = "order_number"
case remark = "photog_remark"
case urgentHour = "urgent_hour"
case cloudFile = "cloud_file"
case uploadFile = "upload_file"
}
}
/// Android `CloudFileItem`
struct TaskCloudFileItem: Encodable, Sendable, Equatable {
let fileId: Int
let remark: String
enum CodingKeys: String, CodingKey {
case fileId = "file_id"
case remark
}
}
/// Android `UploadFileItem`
struct TaskUploadFileItem: Encodable, Sendable, Equatable {
let fileUrl: String
let fileName: String
let remark: String
enum CodingKeys: String, CodingKey {
case fileUrl = "file_url"
case fileName = "file_name"
case remark
}
}
/// Android `AvailableOrderResponse`
struct AvailableOrder: Decodable, Sendable, Equatable, Hashable {
let projectName: String
let orderNumber: String
let orderStatus: Int
let orderStatusLabel: String
let payTime: String
let userId: Int
let userPhone: String
enum CodingKeys: String, CodingKey {
case projectName = "project_name"
case orderNumber = "order_number"
case orderStatus = "order_status"
case orderStatusLabel = "order_status_label"
case payTime = "pay_time"
case userId = "user_id"
case userPhone = "user_phone"
}
init(
projectName: String = "",
orderNumber: String = "",
orderStatus: Int = 0,
orderStatusLabel: String = "",
payTime: String = "",
userId: Int = 0,
userPhone: String = ""
) {
self.projectName = projectName
self.orderNumber = orderNumber
self.orderStatus = orderStatus
self.orderStatusLabel = orderStatusLabel
self.payTime = payTime
self.userId = userId
self.userPhone = userPhone
}
}
///
enum TaskFileSource: String, Sendable, Equatable {
case cloud
case upload
}
/// Android `TaskFileItem`
struct TaskFileItem: Sendable, Equatable, Hashable, Identifiable {
let id: String
let source: TaskFileSource
let cloudFile: CloudFile?
let uploadFileName: String?
let uploadFileType: Int
let uploadTaskId: String?
var uploadFileUrl: String?
var uploadCoverUrl: String?
var remark: String
var isUploading: Bool
var uploadProgress: Int
init(
id: String? = nil,
source: TaskFileSource,
cloudFile: CloudFile? = nil,
uploadFileUrl: String? = nil,
uploadFileName: String? = nil,
uploadFileType: Int = 0,
uploadCoverUrl: String? = nil,
remark: String = "",
uploadTaskId: String? = nil,
isUploading: Bool = false,
uploadProgress: Int = 0
) {
if let id {
self.id = id
} else if source == .cloud, let cloudFile {
self.id = "cloud_\(cloudFile.id)"
} else if let uploadTaskId {
self.id = "upload_\(uploadTaskId)"
} else {
self.id = UUID().uuidString
}
self.source = source
self.cloudFile = cloudFile
self.uploadFileUrl = uploadFileUrl
self.uploadFileName = uploadFileName
self.uploadFileType = uploadFileType
self.uploadCoverUrl = uploadCoverUrl
self.remark = remark
self.uploadTaskId = uploadTaskId
self.isUploading = isUploading
self.uploadProgress = uploadProgress
}
/// URL
var previewURLString: String {
switch source {
case .cloud:
let cover = cloudFile?.coverUrl ?? ""
if !cover.isEmpty { return cover }
return cloudFile?.fileUrl ?? ""
case .upload:
if uploadFileType == 1 {
return uploadCoverUrl ?? uploadFileUrl ?? ""
}
return uploadFileUrl ?? ""
}
}
/// 1=2=
var fileType: Int {
switch source {
case .cloud:
return cloudFile?.type ?? 0
case .upload:
return uploadFileType
}
}
///
var displayName: String {
switch source {
case .cloud:
return cloudFile?.name ?? ""
case .upload:
return uploadFileName ?? ""
}
}
}