using System;
using Statistics;
using UnityEngine;

public class Log
{
    public int damageTakenByDefs = 0;
    public int damageTakenByAtc = 0;

    public int AtcWin = 0;
    public int DefWin = 0;

    public int TimeOuts = 0;
}

public class StatisticManager : MonoBehaviour
{
    private Log _log = new Log();
    private LoggerSideChannel _myLoggerSideChannel = new LoggerSideChannel();
    private void Awake()
    {
        foreach (var npc in GameObject.FindObjectsOfType<NPC>())
            npc.OnDamageReceived += RegisterDamage;

        GlobalEventManager.OnCaptureFlag += RegisterWin;
        GlobalEventManager.OnTimeLeft += RegisterTimeOut;
        GameManager.OnResetScene += SendMessage;
        
    }

    private void RegisterDamage(int damage, Team team)
    {
        if (team == Team.Attackers)
            _log.damageTakenByAtc += damage;
        else
            _log.damageTakenByDefs += damage;
    }

    private void RegisterWin(Team team)
    {
        if (team == Team.Attackers)
            _log.AtcWin += 1;
        else
            _log.DefWin += 1;
    }

    private void RegisterTimeOut()
    {
        _log.TimeOuts += 1;
    }

    private void SendMessage()
    {
        _myLoggerSideChannel.SendLog(_log);
    }
}
