2015-07-19 23:05:30 +00:00
|
|
|
using System.Collections.Generic;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
2015-07-19 23:05:30 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Models
|
2015-07-19 23:05:30 +00:00
|
|
|
{
|
|
|
|
public class TorznabCategory
|
|
|
|
{
|
2015-07-28 23:10:04 +00:00
|
|
|
public int ID { get; set; }
|
2015-07-19 23:05:30 +00:00
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
public List<TorznabCategory> SubCategories { get; private set; }
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public TorznabCategory() => SubCategories = new List<TorznabCategory>();
|
2015-07-29 19:30:28 +00:00
|
|
|
|
2015-08-12 05:41:12 +00:00
|
|
|
public TorznabCategory(int id, string name)
|
|
|
|
{
|
|
|
|
ID = id;
|
|
|
|
Name = name;
|
|
|
|
SubCategories = new List<TorznabCategory>();
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public bool Contains(TorznabCategory cat) =>
|
|
|
|
Equals(this, cat) || SubCategories.Contains(cat);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public JToken ToJson() =>
|
|
|
|
new JObject
|
|
|
|
{
|
|
|
|
["ID"] = ID,
|
|
|
|
["Name"] = Name
|
|
|
|
};
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public override bool Equals(object obj) => (obj as TorznabCategory)?.ID == ID;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
// Get Hash code should be calculated off read only properties.
|
|
|
|
// ID is not readonly
|
|
|
|
public override int GetHashCode() => ID;
|
2015-07-19 23:05:30 +00:00
|
|
|
}
|
|
|
|
}
|