using System.Text.Json.Serialization;

namespace Blahblah.FlowerStory.Server;

/// <summary>
/// 常数类
/// </summary>
public sealed class Constants
{
    /// <summary>
    /// 其他分类
    /// </summary>
    public const string CategoryOther = "other";
    /// <summary>
    /// 未知事件
    /// </summary>
    public const string EventUnknown = "unknown";

    /// <summary>
    /// 类别字典
    /// </summary>
    public static readonly Dictionary<int, NamedItem> Categories = new()
    {
        [0] = new(CategoryOther, "其他"),
        [1] = new("cactus", "仙人球"),
        [2] = new("hibiscus", "扶桑花"),
        [3] = new("bougainvillea", "三角梅"),
        [4] = new("sunflower", "太阳花"),
        [5] = new("milanflower", "米兰花"),
        [6] = new("jasmine", "茉莉花"),
        [7] = new("periwinkle", "长春花"),
        [8] = new("nasturtium", "旱金莲"),
        [9] = new("mirabilis", "紫薇花"),
        [10] = new("tigerthornplum", "虎刺梅"),
        [11] = new("geranium", "天竺葵"),
        [12] = new("ballorchid", "球兰"),
        [13] = new("medalchrysanthemum", "勋章菊"),
        [14] = new("dianthus", "石竹"),
        [15] = new("fivecolorplum", "五色梅"),
        [16] = new("fuchsia", "倒挂金钟"),
        [17] = new("bamboocrabapple", "竹节海棠"),
        [18] = new("impatiens", "凤仙花"),
        [19] = new("beautysakura", "美女樱"),
        [20] = new("petunias", "矮牵牛"),
        [21] = new("desertrose", "沙漠玫瑰"),
        [22] = new("trailingcampanula", "蔓性风铃花"),
        [23] = new("chineserose", "月季花"),
    };

    /// <summary>
    /// 事件字典
    /// </summary>
    public static readonly Dictionary<int, Event> Events = new()
    {
        [(int)EventTypes.Unknown] = new(EventUnknown, "未知"),
        [(int)EventTypes.Buy] = new("buy", "购买", true),
        [(int)EventTypes.Born] = new("born", "出生", true),
        [3] = new("changebasin", "换盆"),
        [4] = new("watering", "浇水"),
        [5] = new("fertilize", "施肥"),
        [6] = new("germination", "发芽"),
        [7] = new("blossom", "开花"),
        [8] = new("fallenleaves", "落叶"),
        [9] = new("prune", "修剪"),
        [10] = new("sick", "生病"),
        [(int)EventTypes.Death] = new("death", "死亡", true),
        [(int)EventTypes.Sell] = new("sell", "出售", true),
        [(int)EventTypes.Share] = new("share", "分享"),
    };
}

/// <summary>
/// 事件类型枚举
/// </summary>
public enum EventTypes
{
    /// <summary>
    /// 未知
    /// </summary>
    Unknown = 0,
    /// <summary>
    /// 购买
    /// </summary>
    Buy = 1,
    /// <summary>
    /// 出生
    /// </summary>
    Born = 2,
    /// <summary>
    /// 死亡
    /// </summary>
    Death = 11,
    /// <summary>
    /// 出售
    /// </summary>
    Sell = 12,
    /// <summary>
    /// 分享
    /// </summary>
    Share = 13,
}

/// <summary>
/// 事件类
/// </summary>
/// <param name="Name">名称</param>
/// <param name="Description">描述</param>
/// <param name="Unique">是否唯一</param>
public record Event(string Name, string? Description = null, bool Unique = false) : NamedItem(Name, Description)
{
    /// <summary>
    /// 是否唯一
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
    public bool Unique { get; init; } = Unique;
}

/// <summary>
/// 命名对象类
/// </summary>
/// <param name="Name">名称</param>
/// <param name="Description">描述</param>
public record NamedItem(string Name, string? Description = null)
{
    /// <summary>
    /// 名称
    /// </summary>
    public string Name { get; init; } = Name;

    /// <summary>
    /// 描述
    /// </summary>
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
    public string? Description { get; init; } = Description;
}
