import { z } from 'zod';
import { type OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
import {
	{{ modelUpperCase }}CreateBodySchema,
	{{ modelUpperCase }}UpdateBodySchema,
	{{ modelUpperCase }}ResponseSchema,
	{{ modelUpperCase }}ListResponseSchema,
} from '#contracts/{{ domainPath }}{{ modelKebabCase }}/schema';
import { ApiResponseSchema, QueryParamsSchema } from '#contracts/shared';

export function register{{ modelUpperCase }}Paths(registry: OpenAPIRegistry): void {
	registry.registerPath({
		method: 'get',
		path: '/api/v1/{{ apiPathLink }}',
		operationId: 'get{{ modelCamelCasePlural }}',
		tags: ['{{ modelReadableNamePlural }}'],
		summary: 'Get all {{ modelReadableNamePluralLower }}',
		security: [{ BearerAuth: [] }],
		request: {
			query: QueryParamsSchema,
		},
		responses: {
			200: { description: 'OK', content: { 'application/json': { schema: {{ modelUpperCase }}ListResponseSchema } } },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
		},
	});

	registry.registerPath({
		method: 'post',
		path: '/api/v1/{{ apiPathLink }}',
		operationId: 'create{{ modelUpperCase }}',
		tags: ['{{ modelReadableNamePlural }}'],
		summary: 'Create {{ modelReadableNameLower }}',
		security: [{ BearerAuth: [] }],
		request: {
			body: { required: true, content: { 'application/json': { schema: {{ modelUpperCase }}CreateBodySchema } } },
		},
		responses: {
			200: { description: 'Created', content: { 'application/json': { schema: {{ modelUpperCase }}ResponseSchema } } },
			400: { description: 'Bad Request' },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
		},
	});

	registry.registerPath({
		method: 'get',
		path: '/api/v1/{{ apiPathLink }}/{id}',
		operationId: 'get{{ modelUpperCase }}ById',
		tags: ['{{ modelReadableNamePlural }}'],
		summary: 'Get {{ modelReadableNameLower }} by ID',
		security: [{ BearerAuth: [] }],
		request: { params: z.object({ id: z.uuid() }) },
		responses: {
			200: { description: 'OK', content: { 'application/json': { schema: {{ modelUpperCase }}ResponseSchema } } },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
			404: { description: 'Not Found' },
		},
	});

	registry.registerPath({
		method: 'put',
		path: '/api/v1/{{ apiPathLink }}/{id}',
		operationId: 'update{{ modelUpperCase }}',
		tags: ['{{ modelReadableNamePlural }}'],
		summary: 'Update {{ modelReadableNameLower }}',
		security: [{ BearerAuth: [] }],
		request: {
			params: z.object({ id: z.uuid() }),
			body: { content: { 'application/json': { schema: {{ modelUpperCase }}UpdateBodySchema } } },
		},
		responses: {
			200: { description: 'Updated', content: { 'application/json': { schema: {{ modelUpperCase }}ResponseSchema } } },
			400: { description: 'Bad Request' },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
			404: { description: 'Not Found' },
		},
	});

	registry.registerPath({
		method: 'delete',
		path: '/api/v1/{{ apiPathLink }}/{id}',
		operationId: 'delete{{ modelUpperCase }}',
		tags: ['{{ modelReadableNamePlural }}'],
		summary: 'Delete {{ modelReadableNameLower }}',
		security: [{ BearerAuth: [] }],
		request: { params: z.object({ id: z.uuid() }) },
		responses: {
			200: {
				description: 'Deleted',
				content: { 'application/json': { schema: ApiResponseSchema(z.null()) } },
			},
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
			404: { description: 'Not Found' },
		},
	});
}
