using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public enum ItemCategory
{
    Material = 1,
    Recipe = 2,
    Pan = 3,
}

public enum ShopItemType
{
    Consumable = 1,
    NonConsumable = 2,
}

public enum ProductRarity
{
    Normal = 1,
    Yellow = 2,
    Copper = 3,
    Silver = 4,
    Gold = 5,
    Rainbow = 6,
}

public enum CornFieldUpgradeType
{
    FieldTop = 1,
    FieldCenter = 2,
    FieldBottom = 3,
    Machine = 4,
}

public enum MissionCategory
{
    Normal = 1,
    Daily = 2,
}

public enum MissionCondition
{
    CornCount = 1,
    CustomerCount = 2,
    SalesCount = 3,
    RareSalesCount = 4,
    RecipeCount = 5,
    CoinConsumeCount = 6,
    SaltSalesCount = 7,
}

public enum MissionRewardType
{
    Coin = 1,
}

[Serializable]
public sealed class MissionData
{
    public int id;
    public int category;
    public int shopLevel;
    public int condition;
    public int count;
    public int rewardType;
    public int reward;
    public MissionCategory Category => (MissionCategory) category;
    public MissionCondition Condition => (MissionCondition) condition;
    public MissionRewardType RewardType => (MissionRewardType) rewardType;
}

[Serializable]
public sealed class RarityData
{
    public int id;
    public int rate;
    public int bulkOrderBonus;
    public ProductRarity Rarity => (ProductRarity)id;
}

[Serializable]
public sealed class PanData
{
    public int id;
    public int nameId;
    public string name;
    public string text;
    public int rarity;
    public ProductRarity Rarity => (ProductRarity)rarity;
}

[Serializable]
public sealed class FieldUpgradeData
{
    public int type;
    public int level;
    public int price;
    public int harvested;
    public string iconPrefabName;
    public string prefabName;
    public CornFieldUpgradeType Type => (CornFieldUpgradeType) type;

    public RectTransform GetIconPrefab()
    {
        return Resources.Load<RectTransform>("MachineIcons/" + iconPrefabName);
    }

    public Animator GetPrefab()
    {
        return Resources.Load<Animator>("Machines/" + prefabName);
    }
    public static CornFieldUpgradeType PlantTypeToUpgradeType(PlantLineType lineType)
    {
        switch (lineType)
        {
            case PlantLineType.Top:
                return CornFieldUpgradeType.FieldTop;
            case PlantLineType.Center:
                return CornFieldUpgradeType.FieldCenter;
            case PlantLineType.Bottom:
                return CornFieldUpgradeType.FieldBottom;
            default:
                throw new ArgumentOutOfRangeException(nameof(lineType), lineType, null);
        }
    }
}

[Serializable]
public sealed class ProductData 
{
    public int id;
    public int nameId;
    public string name;
    public int shopLevel;
    public int price;
    public int volume;
    public int material1Id;
    public int material2Id;
    public int material3Id;
    // public int cookingType;
    public string prefabName;
    public string productPrefabName;
    private List<(int id, int amount)> materialList;
    public List<(int id, int amount)> MaterialList
    {
        get
        {
            if (materialList == null)
            {
                materialList = new List<(int id, int amount)>
                {
                    (material1Id,15 * volume),
                    (material2Id,1),
                    (material3Id,1),
                };
            }
            return materialList;
        }
    }

    public int GetMaterialCount()
    {
        return materialList.Count(material => material.id != Const.NotSetMaterialId);
    }
}

[Serializable]
public sealed class ShopLevelData
{
    public int id;
    public int shopLevel;
    public int heart;
    public int customer;
    public int achievement;
    public string text;
}

[Serializable]
public sealed class ShopData {
    public int id;
    public int nameId;
    public int itemId;
    public string name;
    public int price;
    public string text;
    public int category;
    public int consumeType;
    public string prefabName;
    public ItemCategory Category => (ItemCategory)category;
    public ShopItemType ConsumeType => (ShopItemType)consumeType;
}