using System.Collections.Generic;
using UnityEngine;

[System.Serializable] //Inventory 클래스 정의, 어트리뷰트를 통해 시각적 편집 활용
public class InventoryItem {
    public string itemName;
    public int quantity;

    public InventoryItem(string itemName, int quantity) {
        this.itemName = itemName;
        this.quantity = quantity;
    }
}

public class PlayerInventory : MonoBehaviour { //플레이어 인벤토리 클래스
    public List<InventoryItem> items = new List<InventoryItem>(); //(객체의)리스트로 구현

    // 인벤토리에 아이템 추가
    public void AddItem(string itemName, int quantity) {
        InventoryItem existingItem = items.Find(item => item.itemName == itemName);
        if (existingItem != null) {
            existingItem.quantity += quantity;
        } else {
            items.Add(new InventoryItem(itemName, quantity));
        }
    }

    // 인벤토리에서 아이템 제거 ->  창고로 옮길 때
    public void RemoveItem(string itemName, int quantity) {
        InventoryItem existingItem = items.Find(item => item.itemName == itemName);
        if (existingItem != null && existingItem.quantity >= quantity) {
            existingItem.quantity -= quantity;
            if (existingItem.quantity <= 0) {
                items.Remove(existingItem);
            }
        }
    }
}