package com.merakianalytics.kernel.riotapi;

import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import com.google.common.collect.ImmutableMap;
import com.merakianalytics.orianna.types.common.Platform;
import com.merakianalytics.orianna.types.common.Queue;
import com.merakianalytics.orianna.types.common.Tier;
import com.merakianalytics.orianna.types.dto.league.LeagueList;
import com.merakianalytics.orianna.types.dto.league.SummonerLeagues;
import com.merakianalytics.orianna.types.dto.league.SummonerPositions;

@Path("/league/v3")
public class LeagueAPI extends RiotAPIService {
    @Path("/leagues/by-summoner/{summonerId}")
    @GET
    public SummonerLeagues bySummoner(@QueryParam("platform") Platform platform, @PathParam("summonerId") final long summonerId) {
        if(platform == null) {
            platform = context.getDefaultPlatform();
        }

        final Map<String, Object> query = ImmutableMap.<String, Object> builder()
            .put("platform", platform)
            .put("summonerId", summonerId)
            .build();

        return context.getPipeline().get(SummonerLeagues.class, query);
    }

    @Path("/challengerleagues/by-queue/{queue}")
    @GET
    public LeagueList challenger(@QueryParam("platform") Platform platform, @PathParam("queue") final Queue queue) {
        if(platform == null) {
            platform = context.getDefaultPlatform();
        }

        if(!Queue.RANKED.contains(queue)) {
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        final Map<String, Object> query = ImmutableMap.<String, Object> builder()
            .put("platform", platform)
            .put("queue", queue)
            .put("tier", Tier.CHALLENGER)
            .build();

        return context.getPipeline().get(LeagueList.class, query);
    }

    @Path("/leagues/{leagueId}")
    @GET
    public LeagueList league(@QueryParam("platform") Platform platform, @PathParam("leagueId") final String leagueId) {
        if(platform == null) {
            platform = context.getDefaultPlatform();
        }

        final Map<String, Object> query = ImmutableMap.<String, Object> builder()
            .put("platform", platform)
            .put("leagueId", leagueId)
            .build();

        return context.getPipeline().get(LeagueList.class, query);
    }

    @Path("/masterleagues/by-queue/{queue}")
    @GET
    public LeagueList master(@QueryParam("platform") Platform platform, @PathParam("queue") final Queue queue) {
        if(platform == null) {
            platform = context.getDefaultPlatform();
        }

        if(!Queue.RANKED.contains(queue)) {
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        final Map<String, Object> query = ImmutableMap.<String, Object> builder()
            .put("platform", platform)
            .put("queue", queue)
            .put("tier", Tier.MASTER)
            .build();

        return context.getPipeline().get(LeagueList.class, query);
    }

    @Path("/positions/by-summoner/{summonerId}")
    @GET
    public SummonerPositions positionsBySummoner(@QueryParam("platform") Platform platform, @PathParam("summonerId") final long summonerId) {
        if(platform == null) {
            platform = context.getDefaultPlatform();
        }

        final Map<String, Object> query = ImmutableMap.<String, Object> builder()
            .put("platform", platform)
            .put("summonerId", summonerId)
            .build();

        return context.getPipeline().get(SummonerPositions.class, query);
    }
}

@@ -532,77 +532,8 @@
 st;%0A
-import com.merakianalytics.orianna.types.dto.league.SummonerLeagues;%0A
 impo
@@ -672,556 +672,8 @@
 e %7B%0A
-    @Path(%22/leagues/by-summoner/%7BsummonerId%7D%22)%0A    @GET%0A    public SummonerLeagues bySummoner(@QueryParam(%22platform%22) Platform platform, @PathParam(%22summonerId%22) final long summonerId) %7B%0A        if(platform == null) %7B%0A            platform = context.getDefaultPlatform();%0A        %7D%0A%0A        final Map%3CString, Object%3E query = ImmutableMap.%3CString, Object%3E builder()%0A            .put(%22platform%22, platform)%0A            .put(%22summonerId%22, summonerId)%0A            .build();%0A%0A        return context.getPipeline().get(SummonerLeagues.class, query);%0A    %7D%0A%0A
     

remove get all leagues for summoner endpoint