package com.wslfinc.cf.sdk.api;

import com.wslfinc.cf.sdk.entities.RatingChange;
import java.util.List;

import com.wslfinc.cf.sdk.entities.Contest;
import com.wslfinc.cf.sdk.entities.RanklistRow;
import com.wslfinc.cf.sdk.entities.User;
import java.time.LocalDateTime;

/**
 *
 * @author Wsl_F
 */
public class CodeForcesAPI {

    private static final CodeForcesAPI instance = new CodeForcesAPI();

    private long totalAPICalls;

    private CodeForcesAPI() {
        totalAPICalls = 0;
    }

    public static CodeForcesAPI getInstance() {
        return instance;
    }

    private void beforeAPICall() {
        totalAPICalls++;
        System.out.println("Doing API request #" + totalAPICalls
                + ": " + LocalDateTime.now());
    }

    public long getTotalAPICalls() {
        return this.totalAPICalls;
    }

    /**
     *
     * @param contestId codeforces contest id (!!! not equals cf round number)
     * @return rating changes
     */
    public List<RatingChange> getRatingChanges(int contestId) {
        beforeAPICall();
        return ContestAPI.getRatingChanges(contestId);
    }

    /**
     *
     * @param gym include gym contests
     * @return rating changes
     */
    public List<Contest> getContestsList(boolean gym) {
        beforeAPICall();
        return ContestAPI.getContestsList(gym);
    }

    /**
     *
     * @param contestId Id of the contest. It is not the round number. It can be
     * seen in contest URL.
     * @param from 1-based index of the standings row to start the ranklist.
     * @param count Number of standing rows to return.
     * @param showUnofficial if true than all participants (virtual, out of
     * competition) are shown. Otherwise, only official contestants are shown.
     * @param contest returning result
     * @param problems returning result
     * @param rows returning result
     * @return successfulness
     */
    public boolean getContestStanding(int contestId, int from, int count, boolean showUnofficial,
            Contest contest, Object problems, List<RanklistRow> rows) {
        beforeAPICall();
        return ContestAPI.getContestStanding(contestId, from, count, showUnofficial, contest, problems, rows);
    }

    /**
     * Returns information about one user.
     *
     * @param handle user handle
     * @return {@code User}
     */
    public User getUserInfo(String handle) {
        beforeAPICall();
        return UserAPI.getUserInfo(handle);
    }

    /**
     * Returns information about one or several users
     *
     * @param handles List of user handles
     * @return {@code List<User>}
     */
    public List<User> getUserInfo(List<String> handles) {
        beforeAPICall();
        return UserAPI.getUserInfo(handles);
    }

    /**
     * Returns rating history of the specified user.
     *
     * @param handle User's handle
     * @return
     */
    public List<RatingChange> getRatingHistory(String handle) {
        beforeAPICall();
        return UserAPI.getRatingHistory(handle);
    }

}

@@ -743,32 +743,190 @@
 .now());%0A    %7D%0A%0A
+    private void afterAPICall() %7B%0A        System.out.println(%22API request #%22 + totalAPICalls + %22 done %22%0A                + %22: %22 + LocalDateTime.now());%0A    %7D%0A%0A
     public long 
@@ -942,24 +942,24 @@
 PICalls() %7B%0A
-
         retu
@@ -1209,38 +1209,59 @@
 Call();%0A        
-return
+List%3CRatingChange%3E result =
  ContestAPI.getR
@@ -1285,16 +1285,63 @@
 estId);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A 
@@ -1512,38 +1512,54 @@
 Call();%0A        
-return
+List%3CContest%3E result =
  ContestAPI.getC
@@ -1576,16 +1576,63 @@
 t(gym);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A 
@@ -2397,22 +2397,32 @@
         
-return
+boolean result =
  Contest
@@ -2506,24 +2506,71 @@
 ems, rows);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A    /
@@ -2761,38 +2761,45 @@
 Call();%0A        
-return
+User result =
  UserAPI.getUser
@@ -2808,24 +2808,71 @@
 fo(handle);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A    /
@@ -3103,38 +3103,51 @@
 Call();%0A        
-return
+List%3CUser%3E result =
  UserAPI.getUser
@@ -3157,24 +3157,71 @@
 o(handles);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A    /
@@ -3438,22 +3438,43 @@
         
-return
+List%3CRatingChange%3E result =
  UserAPI
@@ -3496,21 +3496,68 @@
 ry(handle);%0A
+        afterAPICall();%0A        return result;%0A
     %7D%0A%0A%7D%0A

add logs after API call