import { z } from 'zod';
import { type OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
import {
	IncidentTypeCreateBodySchema,
	IncidentTypeUpdateBodySchema,
	IncidentTypeResponseSchema,
	IncidentTypeListResponseSchema,
} from '#contracts/incident-type/schema';
import { ApiResponseSchema, QueryParamsSchema } from '#contracts/shared';

export function registerIncidentTypePaths(registry: OpenAPIRegistry): void {
	registry.registerPath({
		method: 'get',
		path: '/api/v1/incident-types',
		operationId: 'getIncidentTypes',
		tags: ['Incident Types'],
		summary: 'Get all incident types',
		security: [{ BearerAuth: [] }],
		request: {
			query: QueryParamsSchema,
		},
		responses: {
			200: { description: 'OK', content: { 'application/json': { schema: IncidentTypeListResponseSchema } } },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
		},
	});

	registry.registerPath({
		method: 'post',
		path: '/api/v1/incident-types',
		operationId: 'createIncidentType',
		tags: ['Incident Types'],
		summary: 'Create incident type',
		security: [{ BearerAuth: [] }],
		request: {
			body: { required: true, content: { 'application/json': { schema: IncidentTypeCreateBodySchema } } },
		},
		responses: {
			200: { description: 'Created', content: { 'application/json': { schema: IncidentTypeResponseSchema } } },
			400: { description: 'Bad Request' },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
		},
	});

	registry.registerPath({
		method: 'get',
		path: '/api/v1/incident-types/{id}',
		operationId: 'getIncidentTypeById',
		tags: ['Incident Types'],
		summary: 'Get incident type by ID',
		security: [{ BearerAuth: [] }],
		request: { params: z.object({ id: z.uuid() }) },
		responses: {
			200: { description: 'OK', content: { 'application/json': { schema: IncidentTypeResponseSchema } } },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
			404: { description: 'Not Found' },
		},
	});

	registry.registerPath({
		method: 'put',
		path: '/api/v1/incident-types/{id}',
		operationId: 'updateIncidentType',
		tags: ['Incident Types'],
		summary: 'Update incident type',
		security: [{ BearerAuth: [] }],
		request: {
			params: z.object({ id: z.uuid() }),
			body: { content: { 'application/json': { schema: IncidentTypeUpdateBodySchema } } },
		},
		responses: {
			200: { description: 'Updated', content: { 'application/json': { schema: IncidentTypeResponseSchema } } },
			400: { description: 'Bad Request' },
			401: { description: 'Unauthorized' },
			403: { description: 'Forbidden' },
			404: { description: 'Not Found' },
		},
	});

	registry.registerPath({
		method: 'delete',
		path: '/api/v1/incident-types/{id}',
		operationId: 'deleteIncidentType',
		tags: ['Incident Types'],
		summary: 'Delete incident type',
		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' },
		},
	});
}
