import apiService, { Config } from '@/services/api.service' import type { SqlFunctionDto, UpdateSqlFunctionDto, SqlQueryDto, UpdateSqlQueryDto, CreateSqlQueryDto, ExecuteSqlQueryDto, SqlStoredProcedureDto, UpdateSqlStoredProcedureDto, DeployStoredProcedureDto, SqlViewDto, UpdateSqlViewDto, DeployViewDto, DeployFunctionDto, SqlQueryExecutionResultDto, DatabaseColumnDto, DatabaseTableDto, SqlObjectExplorerDto, } from '@/proxy/sql-query-manager/models' export class SqlObjectManagerService { apiName = 'Default' /** * Get all SQL objects for Object Explorer in a single call */ getAllObjects = (dataSourceCode: string, config?: Partial) => apiService.fetchData( { method: 'GET', url: '/api/app/sql-object-manager/objects', params: { dataSourceCode }, }, { apiName: this.apiName, ...config }, ) // Query Operations createQuery = (input: CreateSqlQueryDto, config?: Partial) => apiService.fetchData( { method: 'POST', url: '/api/app/sql-object-manager/query', data: input, }, { apiName: this.apiName, ...config }, ) updateQuery = (id: string, input: UpdateSqlQueryDto, config?: Partial) => apiService.fetchData( { method: 'PUT', url: `/api/app/sql-object-manager/query/${id}`, data: input, }, { apiName: this.apiName, ...config }, ) deleteQuery = (id: string, config?: Partial) => apiService.fetchData( { method: 'DELETE', url: `/api/app/sql-object-manager/${id}/query`, }, { apiName: this.apiName, ...config }, ) executeQuery = (input: ExecuteSqlQueryDto, config?: Partial) => apiService.fetchData( { method: 'POST', url: '/api/app/sql-object-manager/execute-query', data: input, }, { apiName: this.apiName, ...config }, ) executeSavedQuery = (id: string, config?: Partial) => apiService.fetchData( { method: 'POST', url: `/api/app/sql-object-manager/execute-saved-query/${id}`, }, { apiName: this.apiName, ...config }, ) // Stored Procedure Operations updateStoredProcedure = (id: string, input: UpdateSqlStoredProcedureDto, config?: Partial) => apiService.fetchData( { method: 'PUT', url: `/api/app/sql-object-manager/stored-procedure/${id}`, data: input, }, { apiName: this.apiName, ...config }, ) deleteStoredProcedure = (id: string, config?: Partial) => apiService.fetchData( { method: 'DELETE', url: `/api/app/sql-object-manager/${id}/stored-procedure`, }, { apiName: this.apiName, ...config }, ) deployStoredProcedure = (input: DeployStoredProcedureDto, config?: Partial) => apiService.fetchData( { method: 'POST', url: '/api/app/sql-object-manager/deploy-stored-procedure', data: input, }, { apiName: this.apiName, ...config }, ) // View Operations updateView = (id: string, input: UpdateSqlViewDto, config?: Partial) => apiService.fetchData( { method: 'PUT', url: `/api/app/sql-object-manager/view/${id}`, data: input, }, { apiName: this.apiName, ...config }, ) deleteView = (id: string, config?: Partial) => apiService.fetchData( { method: 'DELETE', url: `/api/app/sql-object-manager/${id}/view`, }, { apiName: this.apiName, ...config }, ) deployView = (input: DeployViewDto, config?: Partial) => apiService.fetchData( { method: 'POST', url: '/api/app/sql-object-manager/deploy-view', data: input, }, { apiName: this.apiName, ...config }, ) // Function Operations updateFunction = (id: string, input: UpdateSqlFunctionDto, config?: Partial) => apiService.fetchData( { method: 'PUT', url: `/api/app/sql-object-manager/function/${id}`, data: input, }, { apiName: this.apiName, ...config }, ) deleteFunction = (id: string, config?: Partial) => apiService.fetchData( { method: 'DELETE', url: `/api/app/sql-object-manager/${id}/function`, }, { apiName: this.apiName, ...config }, ) deployFunction = (input: DeployFunctionDto, config?: Partial) => apiService.fetchData( { method: 'POST', url: '/api/app/sql-object-manager/deploy-function', data: input, }, { apiName: this.apiName, ...config }, ) // Database Metadata Operations getTableColumns = (dataSourceCode: string, schemaName: string, tableName: string, config?: Partial) => apiService.fetchData( { method: 'GET', url: '/api/app/sql-object-manager/table-columns', params: { dataSourceCode, schemaName, tableName }, }, { apiName: this.apiName, ...config }, ) // Smart Save - Analyzes SQL and saves to appropriate table with auto-deploy smartSave = (input: { sqlText: string; dataSourceCode: string; name?: string; description?: string }, config?: Partial) => apiService.fetchData<{ objectType: string; objectId: string; deployed: boolean; message: string }, typeof input>( { method: 'POST', url: '/api/app/sql-object-manager/smart-save', data: input, }, { apiName: this.apiName, ...config }, ) } // Export service instance export const sqlObjectManagerService = new SqlObjectManagerService()