//
// ExerciseDocument+PlanSummary.swift
// Workouts
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//

import Foundation

extension ExerciseDocument {
    /// One-line plan summary for list rows — mirrors `Exercise.planSummary(weightUnit:)`
    /// (`Shared/Model/Entities.swift`) exactly, but works from the on-disk document
    /// rather than the SwiftData cache entity: duration exercises show their hold time
    /// ("3 × 45 sec"), unloaded ones drop the weight ("3 × 12 reps"), weighted ones keep
    /// the full "3 × 10 × 40 lb".
    func planSummary(weightUnit: WeightUnit) -> String {
        switch LoadType(rawValue: loadType) ?? .weight {
        case .duration:
            let m = durationSeconds / 60, s = durationSeconds % 60
            let hold = m > 0 && s > 0 ? "\(m)m \(s)s" : (m > 0 ? "\(m) min" : "\(s) sec")
            return "\(sets) × \(hold)"
        case .none:
            return "\(sets) × \(reps) reps"
        case .weight:
            return "\(sets) × \(reps) × \(weightUnit.format(weight))"
        }
    }
}
