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

public sealed class InteractionsController : MonoBehaviour
{
    [SerializeField]
    private CommunicationsPanel communications = null;
    [SerializeField]
    private MarketUIFoldPanel marketPanel = null;
    [SerializeField]
    private MarketUIFoldPanel explorePanel = null;
    [SerializeField]
    private ServiceUIFoldPanel servicePanel = null;
    [SerializeField]
    private EquipmentUIFoldPanel equipmentPanel = null;
    [SerializeField]
    private Profile profile = null;
    [SerializeField]
    private DialogUI dialog = null;

    private IInteractableObject interactionObject = null;

    public void SetObject(IInteractableObject obj = null) {
        interactionObject = obj;
        if (interactionObject == null)
        {
            communications.Hide();
            HideAll();
            return;
        }
        List<CommunicationsPanel.Type> interactions;
        if (obj is SpaceStantion)
        {
            interactions = new List<CommunicationsPanel.Type>() {
                CommunicationsPanel.Type.Trade,
                CommunicationsPanel.Type.Yard,
                CommunicationsPanel.Type.Service
            };
        }
        else
        {
            interactions = new List<CommunicationsPanel.Type>() {
                CommunicationsPanel.Type.Info,
                CommunicationsPanel.Type.Explore
            };
        }
        communications.ShowVariants(interactions, OnSelectInteraction);
    }

    private void OnSelectInteraction(CommunicationsPanel.Type type)
    {
        if (interactionObject == null)
            return;
        HideAll();
        switch (type)
        {
            case CommunicationsPanel.Type.Trade:
                marketPanel.Show(interactionObject as SpaceStantion);
                break;
            case CommunicationsPanel.Type.Yard:
                equipmentPanel.Show(interactionObject.Name);
                break;
            case CommunicationsPanel.Type.Service:
                servicePanel.Show(interactionObject.Name);
                break;
            case CommunicationsPanel.Type.Info:
                dialog.Show("Destroyed pirate ship");
                break;
            case CommunicationsPanel.Type.Explore:
                dialog.Show($"You find some resources on pirate ship", null, null, (_) => {
                    explorePanel.Show(interactionObject as StarShip);
                });
                break;
        }
    }

    private void HideAll()
    {
        marketPanel.Hide();
        servicePanel.Hide();
        equipmentPanel.Hide();
    }
}
