import Foundation
import StoreKit

@MainActor
final class RatingPromptManager {
    static let shared = RatingPromptManager()

    private let hasRequestedKey = "hasRequestedAppRating"
    private let defaults: UserDefaults

    private init(defaults: UserDefaults = .standard) {
        self.defaults = defaults
    }

    func requestRatingIfNeeded() {
        guard !defaults.bool(forKey: hasRequestedKey) else { return }
        SKStoreReviewController.requestReview()
        defaults.set(true, forKey: hasRequestedKey)
    }
}
