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

public class ContractManager : MonoBehaviour
{
    BrokeragePanel brokeragePanel;

    void Awake()
    {
        brokeragePanel = FindObjectOfType<BrokeragePanel>();    
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public List<City> Destinations()
    {
        return GameManager.Instance().cities;
    }

    public int MaxContracts(City city)
    {
        return 3;
    }

    public Contract BuildContract(City city)
    {
        var contract = Utils.PrefabbedComponent<Contract>("_prefabs/Contract");
        contract.origin = city;
        contract.destination = city;
        while (contract.destination == city)
        {
            contract.destination = RandomDestination();
        }

        contract.tonnage = RandomTonnage();
        contract.value = (int) (city.DistanceTo(contract.destination) * 22) + 20;
        contract.name = "Contract: " + contract.origin.cityName + " to " + contract.destination.cityName;
        return contract;
    }

    public City RandomDestination()
    {
        return Destinations()[(int)Random.Range(0, Destinations().Count)];
    }

    public int RandomTonnage()
    {
        var category = ((int) Random.Range(0, 1)) * 30 + 15;
        var extra = ((int)Random.Range(0, 6)) * 3;
        return category + extra;
    }
}
