//
//  Mood.swift
//  Reflect
//
//  Created by Trey Tartt on 1/5/22.
//

import Foundation
import SwiftUI

enum Mood: Int {
    case horrible
    case bad
    case average
    case good
    case great
    case missing
    case placeholder
    
    var next: Mood {
        var moodValue = self.rawValue
        moodValue -= 1
        if moodValue < 0 {
            moodValue = 4
        }
        return Mood.init(rawValue: moodValue) ?? Mood.horrible
    }
    
    var strValue: String {
        switch self {
        case .horrible:
            return String(localized: "mood_value_horrible")
        case .bad:
            return String(localized: "mood_value_bad")
        case .average:
            return String(localized: "mood_value_average")
        case .good:
            return String(localized: "mood_value_good")
        case .great:
            return String(localized: "mood_value_great")
        case .missing:
            return String(localized: "mood_value_missing")
        case .placeholder:
            return String("placeholder")
        }
    }

    /// Non-localized display name for use in widgets (which don't have access to app's localization)
    var widgetDisplayName: String {
        switch self {
        case .horrible: return "Horrible"
        case .bad: return "Bad"
        case .average: return "Average"
        case .good: return "Good"
        case .great: return "Great"
        case .missing: return "Missing"
        case .placeholder: return "Placeholder"
        }
    }
    
    static var allValues: [Mood] {
        return [Mood.horrible, Mood.bad, Mood.average, Mood.good, Mood.great].reversed()
    }

    #if !os(watchOS)
    var color: Color {
        let moodTint:  MoodTintable.Type = UserDefaultsStore.moodTintable()
        return moodTint.color(forMood: self)
    }

    var icon: Image {
        let moodImages: MoodImagable.Type = UserDefaultsStore.moodMoodImagable()
        return moodImages.icon(forMood: self)
    }

    var graphic: Image {
        switch self {
        case .horrible:
            return Image("HorribleGraphic", bundle: .main)
        case .bad:
            return Image("BadGraphic", bundle: .main)
        case .average:
            return Image("AverageGraphic", bundle: .main)
        case .good:
            return Image("GoodGraphic", bundle: .main)
        case .great:
            return Image("GreatGraphic", bundle: .main)
        case .missing:
            return Image("MissingGraphic", bundle: .main)
        case .placeholder:
            return Image("MissingGraphic", bundle: .main)
        }
    }
    #endif
}

extension Mood: Identifiable {
    var id: Int {
        rawValue
    }
}
