package no.stelar7.api.r4j.pojo.tft.league;

import no.stelar7.api.r4j.basic.constants.types.lol.*;

import java.io.Serializable;
import java.util.*;

public class TFTLeagueList implements Serializable
{
    private static final long serialVersionUID = 3779955487138585327L;
    
    private List<TFTLeagueEntry> entries;
    private String               name;
    private GameQueueType        queue;
    private TierType             tier;
    private String               leagueId;
    
    
    /**
     * Takes in a summonerId, and returns the TierDivisionType created from it.
     * Returns UNRANKED if the id is not found
     *
     * @param id the id to use for construction
     * @return TierDivisionType
     */
    public TierDivisionType getTierDivisionType(String id)
    {
        TFTLeagueEntry pos = getLeagueEntry(id);
        
        return pos == null ? TierDivisionType.UNRANKED : pos.getTierDivisionType(tier);
    }
    
    /**
     * Takes in a summonerId, and returns the LeagueItem found in the list.
     * Returns null if not found
     *
     * @param id the Tier to use for construction
     * @return LeagueEntry
     */
    public TFTLeagueEntry getLeagueEntry(String id)
    {
        return entries.stream().filter(s -> s.getSummonerId().equals(id)).findFirst().orElse(null);
    }
    
    @Override
    public boolean equals(Object o)
    {
        if (this == o)
        {
            return true;
        }
        if (o == null || getClass() != o.getClass())
        {
            return false;
        }
        
        TFTLeagueList that = (TFTLeagueList) o;
        
        if (!Objects.equals(entries, that.entries))
        {
            return false;
        }
        if (!Objects.equals(name, that.name))
        {
            return false;
        }
        if (queue != that.queue)
        {
            return false;
        }
        if (tier != that.tier)
        {
            return false;
        }
        return Objects.equals(leagueId, that.leagueId);
    }
    
    @Override
    public int hashCode()
    {
        int result = entries != null ? entries.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (queue != null ? queue.hashCode() : 0);
        result = 31 * result + (tier != null ? tier.hashCode() : 0);
        result = 31 * result + (leagueId != null ? leagueId.hashCode() : 0);
        return result;
    }
    
    /**
     * The requested league entries.
     *
     * @return the entries
     */
    public List<TFTLeagueEntry> getEntries()
    {
        return this.entries;
    }
    
    /**
     * This name is an internal place-holder name only. Display and localization of names in the game client are handled client-side.
     *
     * @return the name
     */
    public String getLeagueName()
    {
        return this.name;
    }
    
    /**
     * ID of the league
     *
     * @return String
     */
    public String getLeagueId()
    {
        return leagueId;
    }
    
    
    /**
     * The league's queue type. (Legal values: RANKED_SOLO_5x5, RANKED_TEAM_3x3, RANKED_TEAM_5x5)
     *
     * @return the queue
     */
    public GameQueueType getQueueType()
    {
        return this.queue;
    }
    
    /**
     * The league's tier. (Legal values: CHALLENGER, MASTER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE)
     *
     * @return the tier
     */
    public TierType getTier()
    {
        return this.tier;
    }
    
    @Override
    public String toString()
    {
        return "LeagueList{" +
               "entries=" + entries +
               ", name='" + name + '\'' +
               ", queue='" + queue + '\'' +
               ", tier='" + tier + '\'' +
               '}';
    }
}

@@ -996,18 +996,22 @@
 the 
+TFT
 League
-Item
+Entry
  fou
@@ -3094,57 +3094,62 @@
 es: 
-RANKED_SOLO_5x5, 
+TEAMFIGHT_TACTICS_
 RANKED
-_
+, 
 TEAM
-_3x3, RANKED_TEAM_5x5
+FIGHT_TACTICS_HYPER_ROLL
 )%0A  
@@ -3378,16 +3378,51 @@
 , BRONZE
+, ORANGE, PURPLE, BLUE, GREEN, GRAY
 )%0A     *
@@ -3592,16 +3592,19 @@
 return %22
+TFT
 LeagueLi
@@ -3714,17 +3714,16 @@
 , queue=
-'
 %22 + queu
@@ -3725,23 +3725,16 @@
  queue +
- '%5C'' +
 %0A       
@@ -3749,17 +3749,16 @@
 %22, tier=
-'
 %22 + tier
@@ -3759,16 +3759,59 @@
 + tier +
+%0A               %22, leagueId='%22 + leagueId +
  '%5C'' +%0A

change toString in TFTLeagueList