132 lines
3.8 KiB
Swift
132 lines
3.8 KiB
Swift
import Foundation
|
||
|
||
// MARK: - Blind Box Media Type
|
||
enum BlindBoxMediaType {
|
||
case video
|
||
case image
|
||
case all
|
||
}
|
||
|
||
// MARK: - Blind Box List
|
||
struct BlindList: Codable, Identifiable {
|
||
// API 返回为字符串,这里按字符串处理
|
||
let id: String
|
||
let boxCode: String
|
||
let userId: String
|
||
let name: String
|
||
let boxType: String
|
||
let features: String?
|
||
let resultFile: FileInfo?
|
||
let status: String
|
||
let workflowInstanceId: String?
|
||
let videoGenerateTime: String?
|
||
let createTime: String
|
||
let coverFile: FileInfo?
|
||
let description: String?
|
||
|
||
struct FileInfo: Codable {
|
||
let id: String
|
||
let fileName: String?
|
||
let url: String?
|
||
// 为了兼容任意元数据结构,这里使用字典的最宽松版本
|
||
// 如果后续需要更强类型,可以引入自定义的 AnyCodable/JSONValue
|
||
let metadata: [String: String]?
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case id
|
||
case fileName = "file_name"
|
||
case url
|
||
case metadata
|
||
}
|
||
}
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case id
|
||
case boxCode = "box_code"
|
||
case userId = "user_id"
|
||
case name
|
||
case boxType = "box_type"
|
||
case features
|
||
case resultFile = "result_file"
|
||
case status
|
||
case workflowInstanceId = "workflow_instance_id"
|
||
case videoGenerateTime = "video_generate_time"
|
||
case createTime = "create_time"
|
||
case coverFile = "cover_file"
|
||
case description
|
||
}
|
||
}
|
||
|
||
// MARK: - Blind Box Count
|
||
struct BlindCount: Codable {
|
||
let availableQuantity: Int
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case availableQuantity = "available_quantity"
|
||
}
|
||
}
|
||
|
||
// MARK: - Blind Box Data
|
||
struct BlindBoxData: Codable {
|
||
let id: Int64
|
||
let boxCode: String
|
||
let userId: Int64
|
||
let name: String
|
||
let boxType: String
|
||
let features: String?
|
||
let url: String?
|
||
let status: String
|
||
let workflowInstanceId: String?
|
||
// 视频生成时间
|
||
let videoGenerateTime: String?
|
||
let createTime: String
|
||
let description: String?
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case id
|
||
case boxCode = "box_code"
|
||
case userId = "user_id"
|
||
case name
|
||
case boxType = "box_type"
|
||
case features
|
||
case url
|
||
case status
|
||
case workflowInstanceId = "workflow_instance_id"
|
||
case videoGenerateTime = "video_generate_time"
|
||
case createTime = "create_time"
|
||
case description
|
||
}
|
||
|
||
init(id: Int64, boxCode: String, userId: Int64, name: String, boxType: String, features: String?, url: String?, status: String, workflowInstanceId: String?, videoGenerateTime: String?, createTime: String, description: String?) {
|
||
self.id = id
|
||
self.boxCode = boxCode
|
||
self.userId = userId
|
||
self.name = name
|
||
self.boxType = boxType
|
||
self.features = features
|
||
self.url = url
|
||
self.status = status
|
||
self.workflowInstanceId = workflowInstanceId
|
||
self.videoGenerateTime = videoGenerateTime
|
||
self.createTime = createTime
|
||
self.description = description
|
||
}
|
||
|
||
init(from listItem: BlindList) {
|
||
self.init(
|
||
id: Int64(listItem.id) ?? 0,
|
||
boxCode: listItem.boxCode,
|
||
userId: Int64(listItem.userId) ?? 0,
|
||
name: listItem.name,
|
||
boxType: listItem.boxType,
|
||
features: listItem.features,
|
||
url: listItem.resultFile?.url,
|
||
status: listItem.status,
|
||
workflowInstanceId: listItem.workflowInstanceId,
|
||
videoGenerateTime: listItem.videoGenerateTime,
|
||
createTime: listItem.createTime,
|
||
description: listItem.description
|
||
)
|
||
}
|
||
}
|