<commit_before>import Foundation

typealias SeasonClosure  = ([Season]) -> ()
typealias EpisodeClosure = (Episode?) -> ()

class DetailsViewModel {
    
    var seasons = [Season]()
    var allSeasons = 0
    var allEpisodes = 0
    var currentSeason = 1
    var currentEpisode = 0
    
    func allSeasons(with imdb: String,
                    provider: DataProvider,
                    callback: @escaping SeasonClosure) -> () {
        
        
        provider.allSeasons(imdb) { (result) in
            switch result {
            case .success(let data):
                callback(self.validateSeason(with: data))
                break
            case .failure(let error):
                print("\(error.localizedDescription)")
//                callback(nil)
                break
            }
        }
    }
    
    func episodeDetails(with imdb: String,
                        provider: DataProvider,
                        episode: Ep,
                        callback: @escaping EpisodeClosure) -> () {

        let ep = getCurrent(episode)
        provider.episodeDetails(imdb, season: currentSeason, episode: ep) { (result) in
            switch result {
            case .success(let data):
                callback(self.validate(with: data))
                break
            case .failure(let error):
                print("\(error.localizedDescription)")
                callback(nil)
                break
            }
        }
    }
    
    private func getCurrent(_ episode: Ep) -> Int {
        switch episode {
        case .first, .next:
            return self.nextEpisode()
        case .previous:
            return self.previousEpisode()
        }
    }
    
    private func previousEpisode() -> Int {
        guard currentEpisode == 1 else {
            currentEpisode -= 1
            return currentEpisode
        }
        if currentSeason > 1 {
            currentSeason -= 1
            
            currentEpisode = getAllEpisodes()
        }
        return currentEpisode
    }
    
    private func nextEpisode() -> Int {
        allEpisodes = getAllEpisodes()
        if currentEpisode == allEpisodes {
            if containsNextSeason() {
                setSeason()
                currentEpisode = 1
                return currentEpisode
            }
            return currentEpisode
        }
        currentEpisode += 1
        return currentEpisode
    }
    
    private func setSeason() {
        currentSeason += 1
    }
    
    private func getAllEpisodes() -> Int {
        guard let episodes : [Episode] = seasons[currentSeason].episodes else {
            return 0
        }
        return episodes.count
    }
    
    private func containsNextSeason() -> Bool {
        if currentSeason < allSeasons {
            return true
        }
        return false
    }

    private func validate(with data: RawData) -> Episode? {
        return ValidateDetailsJson.validate(Episode: data)
    }
    
    private func validateSeason(with data: RawData) -> [Season] {
        self.seasons = ValidateDetailsJson.validate(Season: data)
        self.allSeasons = self.seasons.count - 1
        return self.seasons
    }
}
<commit_msg>changing function to var<commit_after>import Foundation

typealias SeasonClosure  = ([Season]) -> ()
typealias EpisodeClosure = (Episode?) -> ()

class DetailsViewModel {
    
    var seasons = [Season]()
    var allSeasons = 0
    var allEpisodes = 0
    var currentSeason = 1
    var currentEpisode = 0
    
    func allSeasons(with imdb: String,
                    provider: DataProvider,
                    callback: @escaping SeasonClosure) -> () {
        
        
        provider.allSeasons(imdb) { (result) in
            switch result {
            case .success(let data):
                callback(self.validateSeason(with: data))
                break
            case .failure(let error):
                print("\(error.localizedDescription)")
//                callback(nil)
                break
            }
        }
    }
    
    func episodeDetails(with imdb: String,
                        provider: DataProvider,
                        episode: Ep,
                        callback: @escaping EpisodeClosure) -> () {

        let ep = getCurrent(episode)
        provider.episodeDetails(imdb, season: currentSeason, episode: ep) { (result) in
            switch result {
            case .success(let data):
                callback(self.validate(with: data))
                break
            case .failure(let error):
                print("\(error.localizedDescription)")
                callback(nil)
                break
            }
        }
    }
    
    private func getCurrent(_ episode: Ep) -> Int {
        switch episode {
        case .first, .next:
            return self.nextEpisode
        case .previous:
            return self.previousEpisode
        }
    }
    
    private var previousEpisode: Int {
        guard currentEpisode == 1 else {
            currentEpisode -= 1
            return currentEpisode
        }
        if currentSeason > 1 {
            currentSeason -= 1
            
            currentEpisode = getAllEpisodes()
        }
        return currentEpisode
    }
    
    private var nextEpisode: Int {
        allEpisodes = getAllEpisodes()
        if currentEpisode == allEpisodes {
            if containsNextSeason() {
                setSeason()
                currentEpisode = 1
                return currentEpisode
            }
            return currentEpisode
        }
        currentEpisode += 1
        return currentEpisode
    }
    
    private func setSeason() {
        currentSeason += 1
    }
    
    private func getAllEpisodes() -> Int {
        guard let episodes : [Episode] = seasons[currentSeason].episodes else {
            return 0
        }
        return episodes.count
    }
    
    private func containsNextSeason() -> Bool {
        if currentSeason < allSeasons {
            return true
        }
        return false
    }

    private func validate(with data: RawData) -> Episode? {
        return ValidateDetailsJson.validate(Episode: data)
    }
    
    private func validateSeason(with data: RawData) -> [Season] {
        self.seasons = ValidateDetailsJson.validate(Season: data)
        self.allSeasons = self.seasons.count - 1
        return self.seasons
    }
}

{'fraction_non_alphanumeric': 0.08089042169619062, 'fraction_numerical': 0.004075873961435962, 'mean_word_length': 1.4576271186440677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3432369', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1595, 'n_words': 401}