import { z } from 'zod';

export const CreateClientSchema = z.object({
	app_code: z.string().min(1, 'app_code is required').max(100),
	client_id: z.string().min(1, 'client_id is required').max(255),
	client_secret: z.string().max(255).optional(),
	name: z.string().min(1, 'name is required').max(255),
	redirect_uris: z.array(z.string().url()).min(1, 'At least one redirect URI is required'),
	post_logout_redirect_uris: z.array(z.string().url()).default([]),
	grant_types: z.array(z.enum(['authorization_code', 'refresh_token', 'client_credentials', 'implicit'])).default(['authorization_code', 'refresh_token']),
	response_types: z.array(z.enum(['code', 'id_token', 'token', 'none'])).default(['code']),
	scopes: z.array(z.string()).default(['openid', 'profile', 'email']),
	token_endpoint_auth_method: z.enum(['none', 'client_secret_post', 'client_secret_basic', 'client_secret_jwt', 'private_key_jwt']).default('none'),
	require_pkce: z.boolean().default(true),
	status: z.enum(['active', 'inactive', 'suspended']).default('active'),
});

export const UpdateClientSchema = CreateClientSchema.partial().extend({
	client_secret: z.string().max(255).optional(),
});

export const ListClientsQuerySchema = z.object({
	page: z.coerce.number().int().positive().default(1),
	pageSize: z.coerce.number().int().min(1).max(100).default(20),
	status: z.enum(['active', 'inactive', 'suspended']).optional(),
	app_code: z.string().optional(),
	search: z.string().optional(),
});

export const ClientParamsSchema = z.object({
	id: z.string().uuid('Invalid client ID format'),
});

export type CreateClientInput = z.infer<typeof CreateClientSchema>;
export type UpdateClientInput = z.infer<typeof UpdateClientSchema>;
export type ListClientsQuery = z.infer<typeof ListClientsQuerySchema>;
export type ClientParams = z.infer<typeof ClientParamsSchema>;
