swift-chat-core/Sources/MessagingChatCore/Automation/AutomationRule.swift
Lilith dd6fb45493 chore(models): 🔧 Update 11 Swift model files to maintain consistency
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-02-16 02:43:49 -08:00

165 lines
4.2 KiB
Swift

import Foundation
// MARK: - Automation Rule
public struct AutomationRule: Codable, Identifiable, Hashable, Sendable {
public let id: String
public let creatorId: String
public let name: String
public let isEnabled: Bool
public let trigger: AutomationTrigger
public let action: AutomationAction
public let schedule: AutomationSchedule?
public let conditions: [AutomationCondition]
public let createdAt: Date
public let updatedAt: Date
public init(
id: String,
creatorId: String,
name: String,
isEnabled: Bool,
trigger: AutomationTrigger,
action: AutomationAction,
schedule: AutomationSchedule?,
conditions: [AutomationCondition],
createdAt: Date,
updatedAt: Date
) {
self.id = id
self.creatorId = creatorId
self.name = name
self.isEnabled = isEnabled
self.trigger = trigger
self.action = action
self.schedule = schedule
self.conditions = conditions
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
// MARK: - Automation Trigger
public enum AutomationTrigger: Codable, Hashable, Sendable {
case newMessage(fromNewContact: Bool)
case offlineHours
case busyStatus
case keywordMatch(keywords: [String])
case noResponseAfter(minutes: Int)
public var displayName: String {
switch self {
case .newMessage(let fromNew):
return fromNew ? "New contact message" : "Any new message"
case .offlineHours:
return "Outside working hours"
case .busyStatus:
return "Busy status active"
case .keywordMatch(let keywords):
return "Keywords: \(keywords.joined(separator: ", "))"
case .noResponseAfter(let minutes):
return "No response after \(minutes)m"
}
}
}
// MARK: - Automation Action
public enum AutomationAction: Codable, Hashable, Sendable {
case sendAutoReply(message: String)
case archiveThread
case markAsRead
case custom(type: String, payload: RawJSON?)
public var displayName: String {
switch self {
case .sendAutoReply: return "Send auto-reply"
case .archiveThread: return "Archive thread"
case .markAsRead: return "Mark as read"
case .custom(let type, _): return type
}
}
}
// MARK: - Automation Schedule
public struct AutomationSchedule: Codable, Hashable, Sendable {
public let timezone: String
public let activeDays: [DayOfWeek]
public let activeStartTime: String
public let activeEndTime: String
public init(
timezone: String,
activeDays: [DayOfWeek],
activeStartTime: String,
activeEndTime: String
) {
self.timezone = timezone
self.activeDays = activeDays
self.activeStartTime = activeStartTime
self.activeEndTime = activeEndTime
}
}
// MARK: - Day of Week
public enum DayOfWeek: Int, Codable, Hashable, Sendable, CaseIterable {
case sunday = 0
case monday = 1
case tuesday = 2
case wednesday = 3
case thursday = 4
case friday = 5
case saturday = 6
public var shortName: String {
switch self {
case .sunday: return "Sun"
case .monday: return "Mon"
case .tuesday: return "Tue"
case .wednesday: return "Wed"
case .thursday: return "Thu"
case .friday: return "Fri"
case .saturday: return "Sat"
}
}
}
// MARK: - Automation Condition
public struct AutomationCondition: Codable, Hashable, Sendable {
public let field: ConditionField
public let op: ConditionOperator
public let value: String
public init(
field: ConditionField,
op: ConditionOperator,
value: String
) {
self.field = field
self.op = op
self.value = value
}
}
// MARK: - Condition Field
public enum ConditionField: String, Codable, Hashable, Sendable {
case senderRole
case threadAge
case messageCount
case senderVerified
}
// MARK: - Condition Operator
public enum ConditionOperator: String, Codable, Hashable, Sendable {
case equals
case notEquals
case greaterThan
case lessThan
case contains
}