import {
	BucketConfigSchema,
	BucketConfigUpdateSchema,
	StorageAnalyticsResponseSchema,
	StorageDeleteResponseSchema,
	StorageListResponseSchema,
	StoragePresignResponseSchema,
	StorageStatsResponseSchema,
} from './types.ts';
import type { Service } from '../api-reference.ts';

const service: Service = {
	name: 'Object Storage',
	slug: 'object-storage',
	description: 'Store and manage files and binary objects in buckets',
	endpoints: [
		{
			id: 'list-objects',
			title: 'List Objects',
			method: 'GET',
			path: '/storage/objects/{bucket}',
			description: 'List objects in a bucket with optional prefix and pagination.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [
				{
					name: 'prefix',
					type: 'string',
					description: 'Only return keys with this prefix',
					required: false,
				},
				{
					name: 'limit',
					type: 'number',
					description: 'Maximum objects to return',
					required: false,
				},
				{
					name: 'offset',
					type: 'number',
					description: 'Offset for pagination',
					required: false,
				},
			],
			requestBody: null,
			responseDescription: 'Paginated object listing.',
			responseFields: { schema: StorageListResponseSchema },
			statuses: [
				{ code: 200, description: 'Object list returned' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/storage/objects/my-bucket?prefix=images/&limit=50',
		},
		{
			id: 'delete-objects',
			title: 'Delete Objects',
			method: 'DELETE',
			path: '/storage/objects/{bucket}',
			description:
				'Delete objects by key or by prefix. `key` and `prefix` are mutually exclusive query parameters.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [
				{
					name: 'key',
					type: 'string',
					description: 'Delete a single object key',
					required: false,
				},
				{
					name: 'prefix',
					type: 'string',
					description: 'Delete all objects matching prefix',
					required: false,
				},
			],
			requestBody: null,
			responseDescription: 'JSON response with deleted object count.',
			responseFields: { schema: StorageDeleteResponseSchema },
			statuses: [
				{ code: 200, description: 'Delete operation completed' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/storage/objects/my-bucket?key=images/photo.jpg',
		},
		{
			id: 'generate-presigned-url',
			title: 'Generate Presigned URL',
			method: 'GET',
			path: '/storage/presign/{bucket}',
			description: 'Generate a time-limited URL for uploading or downloading an object.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [
				{ name: 'key', type: 'string', description: 'Object key to access', required: true },
				{
					name: 'operation',
					type: 'string',
					description: 'Operation type: `download` or `upload` (default: `download`)',
					required: false,
				},
			],
			requestBody: null,
			responseDescription: 'JSON response containing presigned URL and expiry.',
			responseFields: { schema: StoragePresignResponseSchema },
			statuses: [
				{ code: 200, description: 'Presigned URL generated' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/storage/presign/my-bucket?key=images/photo.jpg&operation=download',
		},
		{
			id: 'get-bucket-stats',
			title: 'Get Bucket Stats',
			method: 'GET',
			path: '/storage/stats/{bucket}',
			description: 'Get object count and total size for a bucket.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [],
			requestBody: null,
			responseDescription: 'Bucket-level usage and activity statistics.',
			responseFields: { schema: StorageStatsResponseSchema },
			statuses: [
				{ code: 200, description: 'Bucket stats returned' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/storage/stats/my-bucket',
		},
		{
			id: 'get-storage-analytics',
			title: 'Get Storage Analytics',
			method: 'GET',
			path: '/storage/analytics',
			description: 'Get aggregated analytics across buckets and daily snapshots.',
			pathParams: [],
			queryParams: [
				{
					name: 'days',
					type: 'number',
					description: 'Days of history to include (default: 180)',
					required: false,
				},
			],
			requestBody: null,
			responseDescription: 'Analytics summary, per-bucket breakdown, and daily trend data.',
			responseFields: { schema: StorageAnalyticsResponseSchema },
			statuses: [
				{ code: 200, description: 'Analytics returned' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/storage/analytics?days=30',
		},
		{
			id: 'get-bucket-config',
			title: 'Get Bucket Config',
			method: 'GET',
			path: '/bucket/config/{bucket}',
			description: 'Retrieve effective configuration for a bucket.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [],
			requestBody: null,
			responseDescription: 'Bucket configuration settings and location metadata.',
			responseFields: { schema: BucketConfigSchema },
			statuses: [
				{ code: 200, description: 'Bucket config returned' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/bucket/config/my-bucket',
		},
		{
			id: 'update-bucket-config',
			title: 'Update Bucket Config',
			method: 'PUT',
			path: '/bucket/config/{bucket}',
			description: 'Update bucket configuration fields. Omitted fields remain unchanged.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [],
			requestBody: {
				description: 'Partial bucket config update payload.',
				fields: { schema: BucketConfigUpdateSchema },
			},
			responseDescription: 'Updated bucket configuration object.',
			responseFields: { schema: BucketConfigSchema },
			statuses: [
				{ code: 200, description: 'Bucket config updated' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/bucket/config/my-bucket',
			exampleBody: { ttl: 86400, public: true, cache_control: 'max-age=3600' },
		},
		{
			id: 'delete-bucket-config',
			title: 'Delete Bucket Config',
			method: 'DELETE',
			path: '/bucket/config/{bucket}',
			description: 'Delete custom bucket config and reset to defaults.',
			pathParams: [{ name: 'bucket', type: 'string', description: 'Bucket name' }],
			queryParams: [],
			requestBody: null,
			responseDescription: 'Empty response on success.',
			statuses: [
				{ code: 200, description: 'Bucket config deleted/reset' },
				{ code: 401, description: 'Unauthorized' },
			],
			examplePath: '/bucket/config/my-bucket',
		},
	],
};

export default service;
