export const adminClientPaths = {
	'/admin/clients': {
		get: {
			tags: ['Admin — OIDC Clients'],
			summary: 'List OIDC clients',
			security: [{ adminApiKey: [] }],
			parameters: [
				{ name: 'page', in: 'query', schema: { type: 'integer', default: 1 } },
				{ name: 'pageSize', in: 'query', schema: { type: 'integer', default: 20 } },
				{ name: 'status', in: 'query', schema: { type: 'string', enum: ['active', 'inactive', 'suspended'] } },
				{ name: 'app_code', in: 'query', schema: { type: 'string' } },
				{ name: 'search', in: 'query', schema: { type: 'string' } },
			],
			responses: { '200': { description: 'OK' }, '401': { description: 'Unauthorized' }, '500': { description: 'Internal Server Error' } },
		},
		post: {
			tags: ['Admin — OIDC Clients'],
			summary: 'Create a new OIDC client',
			security: [{ adminApiKey: [] }],
			requestBody: {
				content: {
					'application/json': {
						schema: { $ref: '#/components/schemas/CreateClient' },
					},
				},
			},
			responses: { '201': { description: 'Created' }, '400': { description: 'Bad Request' }, '401': { description: 'Unauthorized' }, '409': { description: 'Conflict' } },
		},
	},
	'/admin/clients/{id}': {
		get: {
			tags: ['Admin — OIDC Clients'],
			summary: 'Get OIDC client by ID',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '200': { description: 'OK' }, '404': { description: 'Not Found' } },
		},
		put: {
			tags: ['Admin — OIDC Clients'],
			summary: 'Update OIDC client',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			requestBody: {
				content: {
					'application/json': {
						schema: { $ref: '#/components/schemas/UpdateClient' },
					},
				},
			},
			responses: { '200': { description: 'OK' }, '404': { description: 'Not Found' } },
		},
		delete: {
			tags: ['Admin — OIDC Clients'],
			summary: 'Delete OIDC client',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '204': { description: 'No Content' }, '404': { description: 'Not Found' } },
		},
	},
	'/admin/clients/{id}/regenerate-secret': {
		post: {
			tags: ['Admin — OIDC Clients'],
			summary: 'Regenerate client secret',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '200': { description: 'OK' }, '404': { description: 'Not Found' } },
		},
	},
	'/admin/db-connections': {
		get: {
			tags: ['Admin — DB Connections'],
			summary: 'List project database connections',
			security: [{ adminApiKey: [] }],
			parameters: [
				{ name: 'page', in: 'query', schema: { type: 'integer', default: 1 } },
				{ name: 'pageSize', in: 'query', schema: { type: 'integer', default: 20 } },
				{ name: 'status', in: 'query', schema: { type: 'string', enum: ['active', 'inactive'] } },
			],
			responses: { '200': { description: 'OK' } },
		},
		post: {
			tags: ['Admin — DB Connections'],
			summary: 'Create a project database connection',
			security: [{ adminApiKey: [] }],
			requestBody: {
				content: {
					'application/json': {
						schema: { $ref: '#/components/schemas/CreateProjectDbConnection' },
					},
				},
			},
			responses: { '201': { description: 'Created' }, '400': { description: 'Bad Request' } },
		},
	},
	'/admin/db-connections/{id}': {
		get: {
			tags: ['Admin — DB Connections'],
			summary: 'Get project database connection',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '200': { description: 'OK' }, '404': { description: 'Not Found' } },
		},
		put: {
			tags: ['Admin — DB Connections'],
			summary: 'Update project database connection',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '200': { description: 'OK' } },
		},
		delete: {
			tags: ['Admin — DB Connections'],
			summary: 'Delete project database connection',
			security: [{ adminApiKey: [] }],
			parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string', format: 'uuid' } }],
			responses: { '204': { description: 'No Content' } },
		},
	},
	'/admin/db-connections/test': {
		post: {
			tags: ['Admin — DB Connections'],
			summary: 'Test a database connection string',
			security: [{ adminApiKey: [] }],
			requestBody: {
				content: {
					'application/json': {
						schema: { $ref: '#/components/schemas/TestConnection' },
					},
				},
			},
			responses: { '200': { description: 'OK' }, '400': { description: 'Bad Request' } },
		},
	},
	'/admin/health': {
		get: {
			tags: ['Admin — Health'],
			summary: 'SSO server health check',
			security: [{ adminApiKey: [] }],
			responses: { '200': { description: 'OK' }, '503': { description: 'Service Unavailable' } },
		},
	},
};

export const adminComponentSchemas = {
	CreateClient: {
		type: 'object',
		required: ['app_code', 'client_id', 'name', 'redirect_uris'],
		properties: {
			app_code: { type: 'string', example: 'project-a' },
			client_id: { type: 'string', example: 'project-a-client' },
			client_secret: { type: 'string', description: 'Leave empty to auto-generate' },
			name: { type: 'string', example: 'Project A' },
			redirect_uris: { type: 'array', items: { type: 'string', format: 'uri' }, example: ['http://localhost:4000/callback'] },
			post_logout_redirect_uris: { type: 'array', items: { type: 'string', format: 'uri' } },
			grant_types: { type: 'array', items: { type: 'string' }, default: ['authorization_code', 'refresh_token'] },
			response_types: { type: 'array', items: { type: 'string' }, default: ['code'] },
			scopes: { type: 'array', items: { type: 'string' }, default: ['openid', 'profile', 'email'] },
			token_endpoint_auth_method: { type: 'string', default: 'none', enum: ['none', 'client_secret_post', 'client_secret_basic', 'client_secret_jwt', 'private_key_jwt'] },
			require_pkce: { type: 'boolean', default: true },
			status: { type: 'string', default: 'active', enum: ['active', 'inactive', 'suspended'] },
		},
	},
	UpdateClient: {
		type: 'object',
		properties: {
			name: { type: 'string' },
			redirect_uris: { type: 'array', items: { type: 'string', format: 'uri' } },
			post_logout_redirect_uris: { type: 'array', items: { type: 'string', format: 'uri' } },
			scopes: { type: 'array', items: { type: 'string' } },
			token_endpoint_auth_method: { type: 'string', enum: ['none', 'client_secret_post', 'client_secret_basic', 'client_secret_jwt', 'private_key_jwt'] },
			require_pkce: { type: 'boolean' },
			status: { type: 'string', enum: ['active', 'inactive', 'suspended'] },
		},
	},
	CreateProjectDbConnection: {
		type: 'object',
		required: ['app_code', 'connection_string_env'],
		properties: {
			app_code: { type: 'string', example: 'project-a' },
			provider: { type: 'string', default: 'postgresql' },
			connection_string_env: { type: 'string', example: 'DATABASE_URL' },
			user_table: { type: 'string', default: 'users' },
			user_id_column: { type: 'string', default: 'id' },
			email_column: { type: 'string', default: 'email' },
			json_profile_column: { type: 'string' },
			status: { type: 'string', default: 'active' },
		},
	},
	TestConnection: {
		type: 'object',
		required: ['connection_string'],
		properties: {
			connection_string: { type: 'string', description: 'PostgreSQL connection string to test' },
		},
	},
};
