-- test.cue --
package test

import (
	"list"
	"math"
	"strings"
	"time"
)

// String rune constraints
shortString?: strings.MaxRunes(10)
longString?: strings.MinRunes(5)

// Math constraints
multiple?: math.MultipleOf(5)

// Time format constraints
dateTime?: time.Format("2006-01-02T15:04:05Z07:00")
date?: time.Format("2006-01-02")
timeOnly?: time.Format("15:04:05")

// List constraints
shortList?: list.MaxItems(3)
longList?: list.MinItems(5)
boundedList?: list.MaxItems(3) & list.MinItems(5)

// Combined constraints
userName?: string & strings.MinRunes(3) & strings.MaxRunes(20)
score?: int & math.MultipleOf(10)
-- datatest/tests.cue --
package datatest

ok: data: {
	shortString: "foo"
	longString:  "longer string"
	multiple:    20
	dateTime:    "2025-10-02T13:26:30+01:00"
	date:        "2025-10-02"
	timeOnly:    "13:26:30"
	userName:    "roger"
	score:       200
}
stringTooLong: {
	data: shortString: "01234567890"
	error: true
}
stringTooShort: {
	data: longString: "x"
	error: true
}
notMultiple: {
	data: multiple: 1
	error: true
}
badDateTime: {
	data: dateTime: "2025-10-02T13"
	error: true
}
badDate: {
	data: date: "2025-10-40"
	error: true
}
badTime: {
	data: date: "25:00:10"
	error: true
}
badUserName: {
	data: userName: "x"
	error: true
}
badScore2: {
	data: score: 5
	error: true
}
-- out/generate-v3/schema --
{
	$schema: "https://json-schema.org/draft/2020-12/schema"
	type:    "object"
	properties: {
		boundedList: {
			type:     "array"
			maxItems: 3
			minItems: 5
		}
		date: {
			type:   "string"
			format: "date"
		}
		dateTime: {
			type:        "string"
			description: "Time format constraints"
			format:      "date-time"
		}
		longList: {
			type:     "array"
			minItems: 5
		}
		longString: {
			type:      "string"
			minLength: 5
		}
		multiple: {
			type:        "number"
			description: "Math constraints"
			multipleOf:  5
		}
		score: {
			allOf: [{
				type: "number"
			}, {
				type:       "integer"
				multipleOf: 10
			}]
		}
		shortList: {
			type:        "array"
			description: "List constraints"
			maxItems:    3
		}
		shortString: {
			type:        "string"
			description: "String rune constraints"
			maxLength:   10
		}
		timeOnly: {
			type:   "string"
			format: "time"
		}
		userName: {
			type:        "string"
			description: "Combined constraints"
			maxLength:   20
			minLength:   3
		}
	}
}
-- out/generate-v3/badDate --
badDate.data.date: invalid value "2025-10-40" (does not satisfy time.Format("2006-01-02")): invalid time "2025-10-40":
    1:170
    ./datatest/tests.cue:30:14
-- out/generate-v3/badDateTime --
badDateTime.data.dateTime: invalid value "2025-10-02T13" (does not satisfy time.Time): invalid time "2025-10-02T13":
    ./datatest/tests.cue:26:18
    1:255
-- out/generate-v3/badScore2 --
badScore2.data.score: invalid value 5 (does not satisfy math.MultipleOf(10)):
    1:494
    ./datatest/tests.cue:42:15
    1:449
-- out/generate-v3/badTime --
badTime.data.date: invalid value "25:00:10" (does not satisfy time.Format("2006-01-02")): invalid time "25:00:10":
    1:170
    ./datatest/tests.cue:34:14
-- out/generate-v3/badUserName --
badUserName.data.userName: invalid value "x" (does not satisfy strings.MinRunes(3)):
    1:800
    ./datatest/tests.cue:38:18
    1:785
    1:800
-- out/generate-v3/notMultiple --
notMultiple.data.multiple: invalid value 1 (does not satisfy math.MultipleOf(5)):
    1:424
    ./datatest/tests.cue:22:18
-- out/generate-v3/ok --
-- out/generate-v3/stringTooLong --
stringTooLong.data.shortString: invalid value "01234567890" (does not satisfy strings.MaxRunes(10)):
    1:659
    ./datatest/tests.cue:14:21
    1:659
-- out/generate-v3/stringTooShort --
stringTooShort.data.longString: invalid value "x" (does not satisfy strings.MinRunes(5)):
    1:348
    ./datatest/tests.cue:18:20
    1:348
