namespace ReactorMaintenance.Godot.Data;

public sealed class FrontendSession
{
    public FrontendSession(CampaignManifest campaign)
    {
        m_Campaign = campaign;
    }

    public void StartNewCampaign()
    {
        IsRandomLevel = false;
        CampaignIndex = 0;
        HasContinue = true;
    }

    public void ContinueCampaign()
    {
        IsRandomLevel = false;
        HasContinue = true;
    }

    public void StartRandomLevel()
    {
        IsRandomLevel = true;
    }

    public void MarkCurrentLevelLoaded()
    {
        if (!IsRandomLevel)
            HasContinue = true;
    }

    public void AdvanceToNextLevel()
    {
        if (HasNextLevel)
            CampaignIndex++;
    }

    public void CompleteCampaign()
    {
        IsRandomLevel = false;
        CampaignIndex = 0;
        HasContinue = false;
    }

    public bool HasContinue { get; private set; }
    public bool IsRandomLevel { get; private set; }
    public int CampaignIndex { get; private set; }
    public CampaignLevel CurrentLevel => IsRandomLevel ? m_RandomLevel : m_Campaign.Levels[CampaignIndex];
    public int LevelNumber => IsRandomLevel ? 1 : CampaignIndex + 1;
    public int LevelCount => IsRandomLevel ? 1 : m_Campaign.Levels.Count;
    public bool HasNextLevel => !IsRandomLevel && CampaignIndex + 1 < m_Campaign.Levels.Count;
    private readonly CampaignManifest m_Campaign;

    private readonly CampaignLevel m_RandomLevel = new() {
        Id = "random-maintenance",
        Name = "Random Maintenance Shift",
        FlavorText = "A generated shift will use authored JSON level data until generation is implemented.",
        LevelPath = "res://Data/Levels/random_placeholder.json"
    };
}