package ru.redguy.tasks;

import javafx.util.Pair;
import ru.redguy.ATask;
import ru.redguy.Task;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@ATask("3")
public class Task3 extends Task {
    @Override
    public void run() throws IOException {
        HashMap<String, String> albums = new HashMap<>();
        HashMap<String,Integer> a = new HashMap<>();
        Arrays.stream(getFile("альбомы.csv").split("\n"))
                .map(txt -> txt.split(";"))
                .forEach(row -> albums.put(row[0],row[2]));
        Arrays.stream(getFile("треки.csv")
                .split("\n"))
                .map(txt -> txt.split(";"))
                .filter(row -> row[3].equals("1"))
                .map(row -> new Pair<>(albums.get(row[2]), Integer.parseInt(row[4])))
                .forEach(pair -> a.put(pair.getKey(),a.containsKey(pair.getKey())?a.get(pair.getKey())+pair.getValue():pair.getValue()));
        a.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).ifPresent(System.out::println);
    }
}
