//
//  Measurement+String.swift
//  1Weather
//
//  Created by Dmitry Stepanets on 03.03.2021.
//

import Foundation

extension Measurement {
    private static var formatter:MeasurementFormatter {
        let fmt = MeasurementFormatter()
        fmt.unitStyle = .medium
        fmt.numberFormatter.maximumFractionDigits = 0
        return fmt
    }
    
    private static var shortFormatter:MeasurementFormatter {
        let fmt = MeasurementFormatter()
        fmt.unitStyle = .short
        fmt.numberFormatter.maximumFractionDigits = 0
        return fmt
    }
    
    var string:String {
        return Measurement.formatter.string(from: self)
    }
    
    var shortString:String {
        return Measurement.shortFormatter.string(from: self)
    }
}

extension Temperature {
    var localeValue:Double {
        #warning("Hardcoded value!")
        // TODO: replace .fahrenheit with a value from Settings.
        return self.converted(to: .fahrenheit).value.rounded(.down)
    }
}
