<?php

namespace Top100stars\Models;

use Top100stars\Interfaces\IGitTop100CSV;

class TopNLanguage {

    public function __construct(IGitTop100CSV $gitTop100CSV) {
        $this->gitTop100CSV = $gitTop100CSV;
    }    

    public function getNLanguage(int $top, string $language): IGitTop100CSV {
        $results = new GitTop100(null);

        $i=0;
        $csv = $this->gitTop100CSV->getCSV();
        $csv_output = [];
        foreach($csv as $row) {
        if ($row[1]=='top-100-stars' && $row[5]==$language) {
                $csv_output[] = $row;
                if (++$i>=$top) break;
            }
        }
        $results->setCSV($csv_output);
        return $results;
    }
}