//
//  EditOperation.swift
//  CheapRetouch
//
//  Non-destructive editing data model with operation stack.
//

import Foundation

enum ToolType: String, Codable {
    case person
    case object
    case brush
    case move
}

enum EditOperation: Codable {
    case mask(MaskOperation)
    case inpaint(InpaintOperation)
    case adjustment(AdjustmentOperation)
}

struct MaskOperation: Codable, Identifiable {
    let id: UUID
    let toolType: ToolType
    let maskData: Data
    let maskWidth: Int
    let maskHeight: Int
    let timestamp: Date

    init(id: UUID = UUID(), toolType: ToolType, maskData: Data, maskWidth: Int, maskHeight: Int, timestamp: Date = Date()) {
        self.id = id
        self.toolType = toolType
        self.maskData = maskData
        self.maskWidth = maskWidth
        self.maskHeight = maskHeight
        self.timestamp = timestamp
    }
}

struct InpaintOperation: Codable, Identifiable {
    let id: UUID
    let maskOperationId: UUID
    let patchRadius: Int
    let featherAmount: Float
    let timestamp: Date

    init(id: UUID = UUID(), maskOperationId: UUID, patchRadius: Int = 9, featherAmount: Float = 4.0, timestamp: Date = Date()) {
        self.id = id
        self.maskOperationId = maskOperationId
        self.patchRadius = patchRadius
        self.featherAmount = featherAmount
        self.timestamp = timestamp
    }
}

struct AdjustmentOperation: Codable, Identifiable {
    let id: UUID
    let type: AdjustmentType
    let value: Float
    let timestamp: Date

    enum AdjustmentType: String, Codable {
        case brightness
        case contrast
        case saturation
    }

    init(id: UUID = UUID(), type: AdjustmentType, value: Float, timestamp: Date = Date()) {
        self.id = id
        self.type = type
        self.value = value
        self.timestamp = timestamp
    }
}
