/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * 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 org.spongepowered.common.mixin.core.village;

import net.minecraft.item.MerchantOffer;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackComparators;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import javax.annotation.Nullable;

@Mixin(MerchantOffer.class)
public abstract class MerchantOfferMixin {

    @Shadow public abstract net.minecraft.item.ItemStack shadow$getBuyingStackFirst();
    @Shadow @Nullable public abstract net.minecraft.item.ItemStack shadow$getBuyingStackSecond();
    @Shadow public abstract net.minecraft.item.ItemStack shadow$getSellingStack();
    @Shadow public abstract int shadow$getUses();
    @Shadow public abstract int shadow$func_222214_i();
    @Shadow public abstract int shadow$getGivenExp();

    // This is a little questionable, since we're mixing into a Minecraft class.
    // However, Vanilla doesn't override equals(), so no one except plugins
    // should be calling it,
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        MerchantOffer other = (MerchantOffer) o;
        return ItemStackComparators.ALL.get().compare((ItemStack) (Object) this.shadow$getBuyingStackFirst(), (ItemStack) (Object) other.getBuyingStackFirst()) == 0
            && ItemStackComparators.ALL.get().compare((ItemStack) (Object) this.shadow$getBuyingStackSecond(), (ItemStack) (Object) other.getBuyingStackSecond()) == 0
            && ItemStackComparators.ALL.get().compare((ItemStack) (Object) this.shadow$getSellingStack(), (ItemStack) (Object) other.getSellingStack()) == 0
            && this.shadow$getUses() == other.getUses()
            && this.shadow$func_222214_i() == other.func_222214_i()
            && this.shadow$getGivenExp() == other.getGivenExp();
    }
}

@@ -1718,31 +1718,24 @@
 dow$getB
-uyingStackFir
+aseCo
 st
+A
 ();%0A    
@@ -1807,33 +1807,21 @@
 adow$get
-BuyingStackSecond
+CostB
 ();%0A    
@@ -1883,28 +1883,22 @@
 adow$get
-SellingStack
+Result
 ();%0A    
@@ -1982,29 +1982,26 @@
  shadow$
-func_222214_i
+getMaxUses
 ();%0A    
@@ -2038,23 +2038,17 @@
 adow$get
-GivenEx
+X
 p();%0A%0A  
@@ -2579,31 +2579,24 @@
 dow$getB
-uyingStackFir
+aseCo
 st
+A
 (), (Ite
@@ -2626,23 +2626,16 @@
 getB
-uyingStackFir
+aseCo
 st
+A
 ()) 
@@ -2729,33 +2729,21 @@
 adow$get
-BuyingStackSecond
+CostB
 (), (Ite
@@ -2772,25 +2772,13 @@
 .get
-BuyingStackSecond
+CostB
 ()) 
@@ -2872,28 +2872,22 @@
 adow$get
-SellingStack
+Result
 (), (Ite
@@ -2916,20 +2916,14 @@
 .get
-SellingStack
+Result
 ()) 
@@ -3014,46 +3014,40 @@
 dow$
-func_222214_i() == other.func_222214_i
+getMaxUses() == other.getMaxUses
 ()%0A 
@@ -3075,23 +3075,17 @@
 adow$get
-GivenEx
+X
 p() == o
@@ -3096,15 +3096,9 @@
 .get
-GivenEx
+X
 p();

Fix MerchantOffer mixin