import type { OpenAPIV3_1 } from "openapi-types";

export const datamartUpdateSpec: OpenAPIV3_1.PathsObject = {
	"/api/datamart": {
		patch: {
			summary: "Update datamart query",
			description:
				"Update query entry in the datamart. Must be called on the main server. The SQL must be provided as a file upload.",
			tags: ["Datamart"],
			requestBody: {
				required: true,
				content: {
					"multipart/form-data": {
						schema: {
							type: "object",
							properties: {
								name: {
									type: "string",
									example: "active_av",
									description: "Unique name for the query",
								},
								description: {
									type: "string",
									example: "Gets active articles",
									description: "Short explanation of what this query does",
								},
								options: {
									type: "string",
									example: "foo,baz",
									description:
										"Optional comma separated options string passed to the query",
								},
								queryFile: {
									type: "string",
									format: "binary",
									description: "SQL file containing the query text",
								},
							},
						},
					},
				},
			},
			responses: {
				"200": {
					description: "Query successfully created",
					content: {
						"application/json": {
							schema: {
								type: "object",
								properties: {
									success: { type: "boolean", example: true },
									message: {
										type: "string",
										example: "active_av was just added",
									},
								},
							},
						},
					},
				},
				"400": {
					description: "Validation or input error",
					content: {
						"application/json": {
							schema: {
								type: "object",
								properties: {
									success: { type: "boolean", example: false },
									message: {
										type: "string",
										example: "Validation failed",
									},
								},
							},
						},
					},
				},
			},
		},
	},
};
