import { PagedResultDto } from '@/proxy' import apiService from './api.service' import { ApiEndpoint, ApiMigration, CreateUpdateApiEndpointDto, CreateUpdateApiMigrationDto, CreateUpdateCustomComponentDto, CreateUpdateCustomEntityDto, CustomComponent, CustomComponentDto, CustomEntity, } from '@/proxy/developerKit/models' class DeveloperKitService { async getCustomEntities(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/custom-entity', method: 'GET', }) return response.data } async getActiveCustomEntities(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/custom-entity/active-entities', method: 'GET', }) return response.data } async getCustomEntity(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/custom-entity/${id}`, method: 'GET', }) return response.data } async createCustomEntity(data: CreateUpdateCustomEntityDto): Promise { const response = await apiService.fetchData({ url: '/api/app/custom-entity', method: 'POST', data: data as any, }) return response.data } async updateCustomEntity(id: string, entity: CreateUpdateCustomEntityDto): Promise { const response = await apiService.fetchData({ url: `/api/app/custom-entity/${id}`, method: 'PUT', data: entity as any, }) return response.data } async deleteCustomEntity(id: string): Promise { await apiService.fetchData({ url: `/api/app/custom-entity/${id}`, method: 'DELETE', }) } async toggleCustomEntityActiveStatus(id: string): Promise { await apiService.fetchData({ url: `/api/app/custom-entity/${id}/toggle-active-status`, method: 'POST', }) } // Custom Component endpoints async getCustomComponents(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/custom-component', method: 'GET', }) return response.data } async getActiveCustomComponents(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/custom-component/active-components', method: 'GET', }) return response.data } async getCustomComponent(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/custom-component/${id}`, method: 'GET', }) return response.data } async createCustomComponent(component: CreateUpdateCustomComponentDto): Promise { const response = await apiService.fetchData({ url: '/api/app/custom-component', method: 'POST', data: component as any, }) return response.data } async updateCustomComponent( id: string, component: CreateUpdateCustomComponentDto, ): Promise { const response = await apiService.fetchData({ url: `/api/app/custom-component/${id}`, method: 'PUT', data: component as any, }) return response.data } async deleteCustomComponent(id: string): Promise { await apiService.fetchData({ url: `/api/app/custom-component/${id}`, method: 'DELETE', }) } // Migration endpoints async getMigrations(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/api-migration', method: 'GET', }) return response.data } async getMigration(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/api-migration/${id}`, method: 'GET', }) return response.data } async createMigration(data: CreateUpdateApiMigrationDto): Promise { const response = await apiService.fetchData({ url: '/api/app/api-migration', method: 'POST', data: data as any, }) return response.data } async updateMigration(id: string, data: CreateUpdateApiMigrationDto): Promise { const response = await apiService.fetchData({ url: `/api/app/api-migration/${id}`, method: 'PUT', data: data as any, }) return response.data } async deleteMigration(id: string): Promise { await apiService.fetchData({ url: `/api/app/api-migration/${id}`, method: 'DELETE', }) } async applyMigration(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/api-migration/${id}/apply-migration`, method: 'POST', }) return response.data } async getPendingMigrations(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/api-migration/pending-migrations', method: 'GET', }) return response.data } async generateMigration(entityId: string): Promise { const response = await apiService.fetchData({ url: `/api/app/api-migration/generate-migration/${entityId}`, method: 'POST', }) return response.data } // Generated Endpoint endpoints async getGeneratedEndpoints(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/api-endpoint', method: 'GET', }) return response.data } async getActiveGeneratedEndpoints(): Promise> { const response = await apiService.fetchData>({ url: '/api/app/api-endpoint/active-endpoints', method: 'GET', }) return response.data } async getEndpointsByEntity(entityId: string): Promise> { const response = await apiService.fetchData>({ url: `/api/app/api-endpoint/endpoints-by-entity/${entityId}`, method: 'GET', }) return response.data } async getGeneratedEndpoint(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/api-endpoint/${id}`, method: 'GET', }) return response.data } async createGeneratedEndpoint(data: CreateUpdateApiEndpointDto): Promise { const response = await apiService.fetchData({ url: '/api/app/api-endpoint', method: 'POST', data: data as any, }) return response.data } async updateGeneratedEndpoint( id: string, endpoint: CreateUpdateApiEndpointDto, ): Promise { const response = await apiService.fetchData({ url: `/api/app/api-endpoint/${id}`, method: 'PUT', data: endpoint as any, }) return response.data } async deleteGeneratedEndpoint(id: string): Promise { await apiService.fetchData({ url: `/api/app/api-endpoint/${id}`, method: 'DELETE', }) } async toggleGeneratedEndpoint(id: string): Promise { const response = await apiService.fetchData({ url: `/api/app/api-endpoint/${id}/toggle`, method: 'POST', }) return response.data } async generateCrudEndpoints(entityId: string): Promise> { const response = await apiService.fetchData>({ url: `/api/app/api-endpoint/generate-crud-endpoints/${entityId}`, method: 'POST', }) return response.data } // Health Check async healthCheck(): Promise<{ status: string; timestamp: string }> { try { const response = await apiService.fetchData({ url: '/api/app/health', method: 'GET', }) if (response.status === 200) { return { status: 'healthy', timestamp: new Date().toISOString() } } return { status: 'unhealthy', timestamp: new Date().toISOString() } } catch { return { status: 'offline', timestamp: new Date().toISOString() } } } } export const developerKitService = new DeveloperKitService()