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

[System.Serializable]
public class GlobalStatisticsData {

    [SerializeField]
    private uint gamesPlayed = 0;
    public uint GamesPlayed { get { return this.gamesPlayed; } set { this.gamesPlayed = value; } }

    [SerializeField]
    private uint deadCount = 0;
    public uint DeadCount { get { return this.deadCount; } set { this.deadCount = value; } }

    [SerializeField]
    private uint zombiesKilled = 0;
    public uint ZombiesKilled { get { return this.zombiesKilled; } set { this.zombiesKilled = value; } }

    [SerializeField]
    private long timeSpendPlayingTicks = 0;
    public TimeSpan TimeSpendPlaying { get { return TimeSpan.FromTicks(this.timeSpendPlayingTicks); } set { this.timeSpendPlayingTicks = value.Ticks; } }


    public void AssignEvents(GameEvents events) {
        events.OnGameStarted += OnGameStarted;
        events.OnGameFinished += OnGameFinished;
    }

    private void OnGameStarted (CurrentGameData data) {
        this.gamesPlayed++;
    }

    private void OnGameFinished (CurrentGameData data) {

        this.zombiesKilled += data.ZombiesKilled;
        this.TimeSpendPlaying = this.TimeSpendPlaying.Add(data.SessionTime);

        if (data.SessionState != CurrentGameData.SessionStateEnum.FinishedWithSuccess) {
            this.deadCount++;
        }
    }
}
