<commit_before>import UIKit

class CStore:CController
{
    private weak var viewStore:VStore!
    
    override func loadView()
    {
        let viewStore:VStore = VStore(controller:self)
        self.viewStore = viewStore
        view = viewStore
    }
}<commit_msg>store kit<commit_after>import UIKit
import StoreKit

class CStore:CController, SKProductsRequestDelegate, SKPaymentTransactionObserver, SKRequestDelegate
{
    private weak var viewStore:VStore!
    private weak var request:SKProductsRequest?
    let model:MStore
    
    override init()
    {
        model = MStore()
        super.init()
    }
    
    required init?(coder:NSCoder)
    {
        fatalError()
    }
    
    deinit
    {
        request?.cancel()
        SKPaymentQueue.default().remove(self)
    }
    
    override func loadView()
    {
        let viewStore:VStore = VStore(controller:self)
        self.viewStore = viewStore
        view = viewStore
    }
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        SKPaymentQueue.default().add(self)
        
        DispatchQueue.global(qos:DispatchQoS.QoSClass.background).async
            { [weak self] in
                
                guard
                    
                    let purchaseIds:[MStore.PurchaseId] = self?.model.references
                    
                    else
                {
                    return
                }
                
                let purchases:Set<MStore.PurchaseId> = Set<MStore.PurchaseId>(purchaseIds)
                self?.checkAvailabilities(purchases:purchases)
        }
    }
    
    //MARK: private
    
    private func checkAvailabilities(purchases:Set<MStore.PurchaseId>)
    {
        let request:SKProductsRequest = SKProductsRequest(productIdentifiers:purchases)
        self.request = request
        request.delegate = self
        request.start()
    }
    
    //MARK: public
    
    func back()
    {
        parentController.dismissPush(completion:nil)
    }
    
    func restorePurchases()
    {
        DispatchQueue.global(qos:DispatchQoS.QoSClass.background).async
            {
                SKPaymentQueue.default().restoreCompletedTransactions()
        }
    }
    
    func purchase(skProduct:SKProduct?)
    {
        DispatchQueue.global(qos:DispatchQoS.QoSClass.background).async
            {
                guard
                    
                    let skProduct:SKProduct = skProduct
                    
                    else
                {
                    return
                }
                
                let skPayment:SKPayment = SKPayment(product:skProduct)
                SKPaymentQueue.default().add(skPayment)
        }
    }
    
    //MARK: storeKit delegate
    
    func request(_ request:SKRequest, didFailWithError error:Error)
    {
        model.error = error.localizedDescription
        viewStore.refreshStore()
    }
    
    func productsRequest(_ request:SKProductsRequest, didReceive response:SKProductsResponse)
    {
        let products:[SKProduct] = response.products
        
        for product:SKProduct in products
        {
            model.loadSkProduct(skProduct:product)
        }
        
        viewStore.refreshStore()
    }
    
    func paymentQueue(_ queue:SKPaymentQueue, updatedTransactions transactions:[SKPaymentTransaction])
    {
        model.updateTransactions(transactions:transactions)
        viewStore.refreshStore()
    }
    
    func paymentQueue(_ queue:SKPaymentQueue, removedTransactions transactions:[SKPaymentTransaction])
    {
        model.updateTransactions(transactions:transactions)
        viewStore.refreshStore()
    }
    
    func paymentQueueRestoreCompletedTransactionsFinished(_ queue:SKPaymentQueue)
    {
        viewStore.refreshStore()
    }
    
    func paymentQueue(_ queue:SKPaymentQueue, restoreCompletedTransactionsFailedWithError error:Error)
    {
        model.error = error.localizedDescription
        viewStore.refreshStore()
    }
}
{'fraction_non_alphanumeric': 0.07426726279185296, 'fraction_numerical': 0.0, 'mean_word_length': 1.8359154929577466, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2960296', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1038, 'n_words': 164}