-- test.cue --
package test

// matchIf patterns generated by Extract
// These test the reverse transformation in Generate

// Basic if/then/else
basicIfThenElse?: matchIf({
	a!: number
	...
}, {
	b!: number
	...
}, {
	c!: string
	...
})

// If/then only (else is _)
ifThenOnly?: matchIf({
	x!: int
	...
}, {
	y!: int
	...
}, _)

// If only (both then and else are _)
ifOnly?: matchIf({
	foo!: string
	...
}, _, _)

-- datatest/tests.cue --
package datatest

// Matches if condition and then clause
ok1: data: {
	basicIfThenElse: {
		a: 1
		b: 2
	}
	ifThenOnly: {
		x: 1
		y: 2
	}
	ifOnly: {
		foo: "bar"
	}
}

// Matches if condition fails, else clause applies
ok2: data: {
	basicIfThenElse: {
		c: "hello"
	}
}

// Empty objects should be valid
ok3: data: {}

-- out/generate-v3/schema --
{
	$schema:     "https://json-schema.org/draft/2020-12/schema"
	type:        "object"
	description: "matchIf patterns generated by Extract\nThese test the reverse transformation in Generate"
	properties: {
		basicIfThenElse: {
			description: "Basic if/then/else"
			else: {
				type:                 "object"
				additionalProperties: true
				properties: {
					c: {
						type: "string"
					}
				}
				required: ["c"]
			}
			if: {
				type:                 "object"
				additionalProperties: true
				properties: {
					a: {
						type: "number"
					}
				}
				required: ["a"]
			}
			then: {
				type:                 "object"
				additionalProperties: true
				properties: {
					b: {
						type: "number"
					}
				}
				required: ["b"]
			}
		}
		ifOnly: {
			description: "If only (both then and else are _)"
			if: {
				type:                 "object"
				additionalProperties: true
				properties: {
					foo: {
						type: "string"
					}
				}
				required: ["foo"]
			}
		}
		ifThenOnly: {
			description: "If/then only (else is _)"
			if: {
				type:                 "object"
				additionalProperties: true
				properties: {
					x: {
						type: "integer"
					}
				}
				required: ["x"]
			}
			then: {
				type:                 "object"
				additionalProperties: true
				properties: {
					y: {
						type: "integer"
					}
				}
				required: ["y"]
			}
		}
	}
}
-- out/generate-v3/ok1 --
-- out/generate-v3/ok2 --
-- out/generate-v3/ok3 --
