package com.example.shapes

import io.kotest.assertions.json.shouldEqualSpecifiedJson
import kotlin.test.Test

@Suppress("LongMethod")
class ShapeSchemaTest {
    @Test
    fun `Circle demonstrates KDoc and Description annotation`() {
        // Properties with defaults are optional
        Circle::class.jsonSchemaString shouldEqualSpecifiedJson $$"""
        {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "$id": "com.example.shapes.Circle",
            "description": "A circle defined by its radius.",
            "type": "object",
            "properties": {
                "name": {
                  "type": "string"
                },
                "radius": {
                  "type": "number",
                  "description": "Radius in units (must be positive)"
                },
                "color": {
                  "type": "string"
                }
            },
            "required": [
                "name",
                "radius",
                "color"
            ],
            "additionalProperties": false
        }
        """
    }

    @Test
    fun `Shape sealed class generates oneOf schema`() {
        val schema = Shape::class.jsonSchemaString

        schema shouldEqualSpecifiedJson $$"""{
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "$id": "com.example.shapes.Shape",
            "description": "A geometric shape. This sealed class demonstrates polymorphic schema generation.",
            "type": "object",
            "additionalProperties": false,
            "oneOf": [
                {
                    "$ref": "#/$defs/com.example.shapes.Circle"
                },
                {
                    "$ref": "#/$defs/com.example.shapes.Rectangle"
                }
            ],
            "$defs": {
                "com.example.shapes.Circle": {
                    "type": "object",
                    "description": "A circle defined by its radius.",
                    "properties": {
                        "type": {
                            "type": "string",
                            "const": "com.example.shapes.Circle"
                        },
                        "name": {
                            "type": "string"
                        },
                        "radius": {
                            "type": "number",
                            "description": "Radius in units (must be positive)"
                        },
                        "color": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "type",
                        "name",
                        "radius",
                        "color"
                    ],
                    "additionalProperties": false
                },
                "com.example.shapes.Rectangle": {
                    "type": "object",
                    "description": "A rectangle with width and height.",
                    "properties": {
                        "type": {
                            "type": "string",
                            "const": "com.example.shapes.Rectangle"
                        },
                        "name": {
                            "type": "string"
                        },
                        "width": {
                            "type": "number"
                        },
                        "height": {
                            "type": "number",
                            "description": "Height in units"
                        },
                        "color": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "type",
                        "name",
                        "width",
                        "height",
                        "color"
                    ],
                    "additionalProperties": false
                }
            }
        }"""
    }

    @Test
    fun `Drawing contains nested Shape references`() {
        val jsonSchemaString = Drawing::class.jsonSchemaString

        jsonSchemaString shouldEqualSpecifiedJson
            $$"""
            {
              "$schema": "https://json-schema.org/draft/2020-12/schema",
              "$id": "com.example.shapes.Drawing",
              "description": "Container for multiple shapes.",
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Name of this drawing"
                },
                "shapes": {
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/com.example.shapes.Shape"
                  }
                }
              },
              "additionalProperties": false,
              "required": [
                "name",
                "shapes"
              ],
              "$defs": {
                "com.example.shapes.Shape": {
                  "oneOf": [
                    {
                      "$ref": "#/$defs/com.example.shapes.Circle"
                    },
                    {
                      "$ref": "#/$defs/com.example.shapes.Rectangle"
                    }
                  ],
                  "description": "A geometric shape. This sealed class demonstrates polymorphic schema generation."
                },
                "com.example.shapes.Circle": {
                  "type": "object",
                  "description": "A circle defined by its radius.",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "com.example.shapes.Circle"
                    },
                    "name": {
                      "type": "string"
                    },
                    "radius": {
                      "type": "number",
                      "description": "Radius in units (must be positive)"
                    },
                    "color": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "name",
                    "radius",
                    "color"
                  ],
                  "additionalProperties": false
                },
                "com.example.shapes.Rectangle": {
                  "type": "object",
                  "description": "A rectangle with width and height.",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "com.example.shapes.Rectangle"
                    },
                    "name": {
                      "type": "string"
                    },
                    "width": {
                      "type": "number"
                    },
                    "height": {
                      "type": "number",
                      "description": "Height in units"
                    },
                    "color": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "name",
                    "width",
                    "height",
                    "color"
                  ],
                  "additionalProperties": false
                }
              }
            }
            """.trimMargin()
    }
}
