using System;
using System.Collections.Generic;
using System.Linq;

namespace Wizard;

public class DegreeMgr
{
	private List<Degree> _list = new List<Degree>();

	public void Add(Degree degree)
	{
		_list.Add(degree);
	}

	public List<Degree> GetList()
	{
		return _list;
	}

	public bool IsContainsInMaster(int id)
	{
		return _list.Find((Degree x) => x._id == id) != null;
	}

	public Degree Get(int id)
	{
		Degree degree = _list.Find((Degree x) => x._id == id);
		if (degree == null)
		{
			degree = Get(Data.Load.data.DefaultDegreeId);
		}
		if (degree != null && !degree.IsEnableInCurrentLanguage)
		{
			degree = Get(Data.Load.data.DefaultDegreeId);
		}
		return degree;
	}

	public string GetResourcePath(int id)
	{
		return Get(id)._path;
	}

	public string GetMaskTexturePath(int id)
	{
		return $"degree_mask_{Get(id)._id}";
	}

	public void Acquired(int id)
	{
		Get(id).Acquired();
	}

	public void UnsetNew(int id)
	{
		Get(id).UnsetNew();
	}

	public void SetNew(int id)
	{
		Get(id).SetNew();
	}

	public void SetFavorite(int id, bool favorite)
	{
		Get(id).SetFavorite(favorite);
	}

	public IEnumerable<long> GetFavorites()
	{
		return ((IEnumerable<Degree>)_list.FindAll((Degree x) => x.IsFavorite)).Select((Func<Degree, long>)((Degree x) => x._id));
	}
}
