import Foundation
import Models

public struct PendingAction: Sendable, Codable {
	public var id: String
	public var accountId: String
	public var actionType: ActionType
	public var payload: ActionPayload
	public var createdAt: Date

	public init(
		id: String = UUID().uuidString,
		accountId: String,
		actionType: ActionType,
		payload: ActionPayload,
		createdAt: Date = Date()
	) {
		self.id = id
		self.accountId = accountId
		self.actionType = actionType
		self.payload = payload
		self.createdAt = createdAt
	}
}

public enum ActionType: String, Sendable, Codable {
	case setFlags
	case move
	case delete
	case send
	case append
}

public enum ActionPayload: Sendable, Codable {
	case setFlags(uid: Int, mailbox: String, add: [String], remove: [String])
	case move(uid: Int, from: String, to: String)
	case delete(uid: Int, mailbox: String, trashMailbox: String)
	case send(message: OutgoingMessage)
	case append(mailbox: String, messageData: String, flags: [String])

	public var actionType: ActionType {
		switch self {
		case .setFlags: return .setFlags
		case .move: return .move
		case .delete: return .delete
		case .send: return .send
		case .append: return .append
		}
	}
}
