summaryrefslogtreecommitdiff
path: root/Sources/BubombCore/Models/SequenceStep.swift
blob: f1d075dec363d0a69016832ec58fa05abe5c1f55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Foundation

/// Individual step within a Multi-step Sequence payload.
public struct SequenceStep: Identifiable, Codable, Equatable, Hashable, Sendable {
    public var id: UUID
    public var name: String
    public var action: StepAction

    public init(id: UUID = UUID(), name: String, action: StepAction) {
        self.id = id
        self.name = name
        self.action = action
    }

    public enum StepAction: Codable, Equatable, Hashable, Sendable {
        case openApplication(applicationPath: String)
        case openURL(urlString: String)
        case runCommand(command: String, workingDirectory: String?, timeoutSeconds: TimeInterval?)
        case runScript(scriptPath: String, arguments: [String], workingDirectory: String?, timeoutSeconds: TimeInterval?)
    }

    public var actionTypeTitle: String {
        switch action {
        case .openApplication: return "Open App"
        case .openURL: return "Open URL"
        case .runCommand: return "Shell Command"
        case .runScript: return "Run Script"
        }
    }

    public var summary: String {
        switch action {
        case .openApplication(let path):
            return (path as NSString).lastPathComponent
        case .openURL(let url):
            return url
        case .runCommand(let cmd, _, _):
            return cmd
        case .runScript(let path, _, _, _):
            return (path as NSString).lastPathComponent
        }
    }
}