//
//  FixedWidthInteger+Extensions.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 03/03/2024.
//

import Foundation

public extension FixedWidthInteger {
    func ordinalFormattedSuffix(feminine: Bool = false) -> String {
        switch self {
        case 1: return feminine ? "ère" : "er"
        default: return "ème"
        }
    }
    
    func ordinalFormatted(feminine: Bool = false) -> String {
        return self.formatted() + self.ordinalFormattedSuffix(feminine: feminine)
    }
    
    private var isMany: Bool {
        self > 1 || self < -1
    }
    
    var pluralSuffix: String {
        return isMany ? "s" : ""
    }
    
    func localizedPluralSuffix(_ plural: String = "s") -> String {
        return isMany ? plural : ""
    }
    
    func formattedAsRawString() -> String {
        String(self)
    }
    
    func durationInHourMinutes() -> String {
        let duration = Duration.seconds(self*60)
        let formatStyle = Duration.UnitsFormatStyle(allowedUnits: [.hours, .minutes], width: .narrow)
        return formatStyle.format(duration)
    }
}
