/*
 * The MIT License
 * Copyright © 2013 Richard Harrah
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.tealcube.minecraft.bukkit.mythicdrops.repair;

import com.tealcube.minecraft.bukkit.mythicdrops.api.repair.RepairCost;
import com.tealcube.minecraft.bukkit.mythicdrops.items.ItemStackExtensionsKt;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;

import java.util.Collections;
import java.util.List;

public final class MythicRepairCost implements RepairCost {

  private final String name;
  private final int priority;
  private final int experienceCost;
  private final double repairPercentagePerCost;
  private final int amount;
  private final Material material;
  private final String itemName;
  private final List<String> itemLore;

  public MythicRepairCost(String name, int priority, int experienceCost,
      double repairPercentagePerCost, int amount,
      Material material, String itemName, List<String> itemLore) {
    this.name = name;
    this.priority = priority;
    this.experienceCost = experienceCost;
    this.repairPercentagePerCost = repairPercentagePerCost;
    this.amount = amount;
    this.material = material;
    this.itemName = itemName;
    this.itemLore = itemLore;
  }

  @Override
  public List<String> getItemLore() {
    return itemLore;
  }

  @Override
  public String getItemName() {
    return itemName;
  }

  @Override
  public Material getMaterial() {
    return material;
  }

  @Override
  public int getAmount() {
    return amount;
  }

  @Override
  public double getRepairPercentagePerCost() {
    return repairPercentagePerCost;
  }

  @Override
  public int getExperienceCost() {
    return experienceCost;
  }

  @Override
  public int getPriority() {
    return priority;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public ItemStack toItemStack(int amount) {
    ItemStack itemStack = new ItemStack(material, amount);
    ItemStackExtensionsKt.setDisplayNameChatColorized(
            itemStack, (itemName == null || itemName.isEmpty()) ? null : itemName);
    ItemStackExtensionsKt.setLoreChatColorized(
            itemStack, (itemLore == null || itemLore.isEmpty()) ? Collections.emptyList() : itemLore);
    return itemStack;
  }

  @Override
  public int hashCode() {
    int result;
    long temp;
    result = name != null ? name.hashCode() : 0;
    result = 31 * result + priority;
    result = 31 * result + experienceCost;
    temp = Double.doubleToLongBits(repairPercentagePerCost);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    result = 31 * result + amount;
    result = 31 * result + (material != null ? material.hashCode() : 0);
    result = 31 * result + (itemName != null ? itemName.hashCode() : 0);
    result = 31 * result + (itemLore != null ? itemLore.hashCode() : 0);
    return result;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    MythicRepairCost that = (MythicRepairCost) o;

    return amount == that.amount && experienceCost == that.experienceCost
        && priority == that.priority
        && Double.compare(that.repairPercentagePerCost, repairPercentagePerCost) == 0 && !(
        itemLore != null ? !itemLore.equals(that.itemLore) : that.itemLore != null) && !(
        itemName != null ? !itemName.equals(that.itemName) : that.itemName != null)
        && material == that.material && !(name != null ? !name.equals(that.name)
        : that.name != null);
  }
}

@@ -1408,49 +1408,8 @@
 ack;
-%0Aimport org.bukkit.material.MaterialData;
 %0A%0Aim
@@ -1826,16 +1826,23 @@
 airCost(
+%0A      
 String n
@@ -1845,16 +1845,22 @@
 ng name,
+%0A     
  int pri
@@ -1865,16 +1865,22 @@
 riority,
+%0A     
  int exp
@@ -1929,16 +1929,22 @@
 PerCost,
+%0A     
  int amo
@@ -1972,16 +1972,22 @@
 aterial,
+%0A     
  String 
@@ -1995,16 +1995,22 @@
 temName,
+%0A     
  List%3CSt
@@ -3003,24 +3003,77 @@
 l, amount);%0A
+    if (itemName != null && !itemName.isEmpty()) %7B%0A  
     ItemStac
@@ -3110,37 +3110,24 @@
 atColorized(
-%0A            
 itemStack, (
@@ -3125,25 +3125,24 @@
 mStack, 
-(
 itemName
  == null
@@ -3137,59 +3137,17 @@
 Name
- == null %7C%7C itemName.isEmpty()) ? null : itemName);
+);%0A    %7D%0A
 %0A   
@@ -3191,20 +3191,16 @@
 orized(%0A
-    
         
@@ -4166,16 +4166,24 @@
 t.amount
+%0A       
  && expe
@@ -4338,22 +4338,16 @@
 st) == 0
- && !(
 %0A       
@@ -4343,24 +4343,29 @@
 = 0%0A        
+&& !(
 itemLore != 
@@ -4427,22 +4427,16 @@
 != null)
- && !(
 %0A       
@@ -4432,24 +4432,29 @@
 ll)%0A        
+&& !(
 itemName != 
@@ -4553,16 +4553,24 @@
 material
+%0A       
  && !(na
@@ -4605,24 +4605,16 @@
 at.name)
-%0A       
  : that.

fix repair cost toItemStack like repair item