// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0

using GFramework.SourceGenerators.Common.Constants;

namespace GFramework.Game.SourceGenerators.Diagnostics;

/// <summary>
///     提供配置 schema 代码生成相关诊断。
/// </summary>
public static class ConfigSchemaDiagnostics
{
    private const string SourceGeneratorsConfigCategory = $"{PathContests.SourceGeneratorsPath}.Config";

    /// <summary>
    ///     schema JSON 无法解析。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidSchemaJson = new(
        "GF_ConfigSchema_001",
        "Config schema JSON is invalid",
        "Schema file '{0}' could not be parsed: {1}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 顶层必须是 object。
    /// </summary>
    public static readonly DiagnosticDescriptor RootObjectSchemaRequired = new(
        "GF_ConfigSchema_002",
        "Config schema root must describe an object",
        "Schema file '{0}' must declare a root object schema",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 必须声明 id 字段作为主键。
    /// </summary>
    public static readonly DiagnosticDescriptor IdPropertyRequired = new(
        "GF_ConfigSchema_003",
        "Config schema must declare an id property",
        "Schema file '{0}' must declare a required 'id' property for table generation",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 包含暂不支持的字段类型。
    /// </summary>
    public static readonly DiagnosticDescriptor UnsupportedPropertyType = new(
        "GF_ConfigSchema_004",
        "Config schema contains an unsupported property type",
        "Property '{1}' in schema file '{0}' uses unsupported type '{2}'",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 的 id 字段类型不支持作为主键。
    /// </summary>
    public static readonly DiagnosticDescriptor UnsupportedKeyType = new(
        "GF_ConfigSchema_005",
        "Config schema uses an unsupported key type",
        "Schema file '{0}' uses unsupported id type '{1}'. Supported key types are 'integer' and 'string'.",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 字段名无法安全映射为 C# 标识符。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidGeneratedIdentifier = new(
        "GF_ConfigSchema_006",
        "Config schema property name cannot be converted to a valid C# identifier",
        "Property '{1}' in schema file '{0}' uses schema key '{2}', which generates invalid C# identifier '{3}'",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 顶层自定义配置目录元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidConfigRelativePathMetadata = new(
        "GF_ConfigSchema_007",
        "Config schema uses invalid custom config path metadata",
        "Schema file '{0}' uses invalid '{1}' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 字段的查询索引元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidLookupIndexMetadata = new(
        "GF_ConfigSchema_008",
        "Config schema uses invalid lookup index metadata",
        "Property '{1}' in schema file '{0}' uses invalid '{2}' metadata: {3}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 字段的字符串 format 元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidStringFormatMetadata = new(
        "GF_ConfigSchema_009",
        "Config schema uses invalid string format metadata",
        "Property '{1}' in schema file '{0}' uses invalid 'format' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 对象节点的 dependentRequired 元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidDependentRequiredMetadata = new(
        "GF_ConfigSchema_010",
        "Config schema uses invalid dependentRequired metadata",
        "Property '{1}' in schema file '{0}' uses invalid 'dependentRequired' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 对象节点的 dependentSchemas 元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidDependentSchemasMetadata = new(
        "GF_ConfigSchema_011",
        "Config schema uses invalid dependentSchemas metadata",
        "Property '{1}' in schema file '{0}' uses invalid 'dependentSchemas' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 对象节点的 allOf 元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidAllOfMetadata = new(
        "GF_ConfigSchema_012",
        "Config schema uses invalid allOf metadata",
        "Property '{1}' in schema file '{0}' uses invalid 'allOf' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 对象节点的 if/then/else 条件元数据无效。
    /// </summary>
    public static readonly DiagnosticDescriptor InvalidConditionalSchemaMetadata = new(
        "GF_ConfigSchema_013",
        "Config schema uses invalid if/then/else metadata",
        "Property '{1}' in schema file '{0}' uses invalid 'if/then/else' metadata: {2}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 字段名在标识符归一化后发生冲突。
    /// </summary>
    public static readonly DiagnosticDescriptor DuplicateGeneratedIdentifier = new(
        "GF_ConfigSchema_014",
        "Config schema property names collide after C# identifier normalization",
        "Property '{1}' in schema file '{0}' uses schema key '{2}', which generates duplicate C# identifier '{3}' already produced by schema key '{4}'",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 节点声明了当前共享子集尚未支持的组合关键字。
    /// </summary>
    public static readonly DiagnosticDescriptor UnsupportedCombinatorKeyword = new(
        "GF_ConfigSchema_015",
        "Config schema uses an unsupported combinator keyword",
        "Property '{1}' in schema file '{0}' uses unsupported combinator keyword '{2}': {3}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 节点声明了当前共享子集尚未支持的开放对象关键字形状。
    /// </summary>
    public static readonly DiagnosticDescriptor UnsupportedOpenObjectKeyword = new(
        "GF_ConfigSchema_016",
        "Config schema uses an unsupported open-object keyword",
        "Property '{1}' in schema file '{0}' uses unsupported open-object keyword '{2}': {3}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);

    /// <summary>
    ///     schema 节点声明了当前共享子集尚未支持的数组形状关键字。
    /// </summary>
    public static readonly DiagnosticDescriptor UnsupportedArrayShapeKeyword = new(
        "GF_ConfigSchema_017",
        "Config schema uses an unsupported array-shape keyword",
        "Property '{1}' in schema file '{0}' uses unsupported array-shape keyword '{2}': {3}",
        SourceGeneratorsConfigCategory,
        DiagnosticSeverity.Error,
        true);
}
