/*
 * Copyright (C) 2013-2019 Timothy Baxendale
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package tbax.baxshops.notification;

import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tbax.baxshops.BaxEntry;
import tbax.baxshops.BaxShop;
import tbax.baxshops.ShopPlugin;
import tbax.baxshops.serialization.UpgradeableSerialization;
import tbax.baxshops.serialization.SafeMap;
import tbax.baxshops.serialization.StoredPlayer;
import tbax.baxshops.serialization.UpgradeableSerializable;
import tbax.baxshops.serialization.annotations.DoNotSerialize;
import tbax.baxshops.serialization.annotations.SerializeMethod;
import tbax.baxshops.serialization.states.State_00300;

import java.util.Date;
import java.util.Map;
import java.util.UUID;

public abstract class StandardNote implements Notification, UpgradeableSerializable
{
    protected BaxEntry entry;
    protected Date date;

    @SerializeMethod("getBuyer")
    protected UUID buyer;

    @SerializeMethod("getSeller")
    protected UUID seller;

    @DoNotSerialize
    protected UUID shopId;

    public StandardNote(UUID shopId, OfflinePlayer buyer, OfflinePlayer seller, BaxEntry entry)
    {
        this(shopId, buyer.getUniqueId(), seller.getUniqueId(), entry);
    }

    public StandardNote(UUID shopId, UUID buyer, UUID seller, BaxEntry entry)
    {
        this.shopId = shopId;
        this.buyer = buyer;
        this.seller = seller;
        this.entry = new BaxEntry(entry);
        this.date = new Date();
    }

    public StandardNote(Map<String, Object> args)
    {
        UpgradeableSerialization.deserialize(this, args);
    }

    @Deprecated
    public void deserialize00300(@NotNull SafeMap map)
    {
        buyer = State_00300.getPlayerId(map.getString("buyer", StoredPlayer.DUMMY_NAME));
        seller = State_00300.getPlayerId(map.getString("seller", StoredPlayer.DUMMY_NAME));
        shopId = State_00300.getShopId(map.getLong("shopId"));
        entry = map.getBaxEntry("entry");
    }

    @Deprecated
    public void deserialize00400(@NotNull SafeMap map)
    {
        entry = map.getBaxEntry("entry");
        buyer = map.getUUID("buyer");
        seller = map.getUUID("seller");
        shopId = map.getUUID("shopId");
        date = map.getDate("date");
    }

    @Override
    public @Nullable Date getSentDate()
    {
        return date;
    }

    public @NotNull OfflinePlayer getBuyer()
    {
        return ShopPlugin.getOfflinePlayer(buyer);
    }

    public @NotNull OfflinePlayer getSeller()
    {
        return ShopPlugin.getOfflinePlayer(seller);
    }

    public @NotNull BaxEntry getEntry()
    {
        return entry;
    }

    public @NotNull UUID getShopId()
    {
        return shopId;
    }

    @Override
    public @NotNull Map<String, Object> serialize()
    {
        Map<String, Object> args = UpgradeableSerializable.super.serialize();
        args.put("shopId", (shopId == null ? BaxShop.DUMMY_UUID : shopId).toString());
        return args;
    }
}

@@ -1775,21 +1775,16 @@
 ;%0A%0A    @
-DoNot
 Serializ
@@ -1784,16 +1784,35 @@
 erialize
+Method(%22getShopId%22)
 %0A    pro
@@ -3476,110 +3476,40 @@
     
-return shopId;%0A    %7D%0A%0A    @Override%0A    public @NotNull Map%3CString, Object%3E serialize(
+if (shopId == null
 )%0A    
-%7B%0A
         
 Map%3C
@@ -3508,163 +3508,42 @@
     
-Map%3CString, Object%3E args = UpgradeableSerializable.super.serialize();%0A        args.put(%22shopId%22, (shopId == null ? BaxShop.DUMMY_UUID : shopId).toString())
+return shopId = BaxShop.DUMMY_UUID
 ;%0A  
@@ -3555,20 +3555,22 @@
  return 
-args
+shopId
 ;%0A    %7D%0A

Remove serialize override in StandardNote