import type { BulkUpdateMetricVerificationStatusRequest, BulkUpdateMetricVerificationStatusResponse, ShareDeleteRequest, ShareUpdateRequest, DeleteMetricRequest, DeleteMetricResponse, DuplicateMetricRequest, DuplicateMetricResponse, GetMetricDataRequest, ListMetricsResponse, ShareMetricRequest, ShareMetricResponse, UpdateMetricRequest, GetMetricRequest, GetMetricListRequest, ShareDeleteResponse, MetricDataResponse, GetMetricResponse, UpdateMetricResponse, ShareUpdateResponse } from '@buster/server-shared/metrics'; import { serverFetch } from '@/api/createServerInstance'; import { mainApi } from '../instances'; export const getMetric = async (params: GetMetricRequest): Promise => { return mainApi .get(`/metrics/${params.id}`, { params }) .then((res) => res.data); }; export const getMetric_server = async ({ id, password }: Parameters[0]) => { return await serverFetch(`/metrics/${id}`, { params: { ...(password && { password }) } }); }; export const getMetricData = async ({ id, version_number, password }: GetMetricDataRequest): Promise => { return mainApi .get(`/metrics/${id}/data`, { params: { password, version_number } }) .then((res) => res.data); }; export const listMetrics = async (params: GetMetricListRequest) => { return mainApi.get('/metrics', { params }).then((res) => res.data); }; export const listMetrics_server = async (params: Parameters[0]) => { return await serverFetch('/metrics', { params }); }; export const updateMetric = async (params: UpdateMetricRequest) => { return mainApi.put(`/metrics/${params.id}`, params).then((res) => res.data); }; export const deleteMetrics = async (data: DeleteMetricRequest) => { return mainApi .delete('/metrics', { data }) .then((res) => res.data); }; export const duplicateMetric = async (params: DuplicateMetricRequest) => { return mainApi .post('/metrics/duplicate', params) .then((res) => res.data); }; export const bulkUpdateMetricVerificationStatus = async ( params: BulkUpdateMetricVerificationStatusRequest ) => { return mainApi .put('/metrics', params) .then((res) => res.data); }; // share metrics export const shareMetric = async ({ id, params }: { id: string; params: ShareMetricRequest }) => { return mainApi .post(`/metrics/${id}/sharing`, params) .then((res) => res.data); }; export const unshareMetric = async ({ id, data }: { id: string; data: ShareDeleteRequest }) => { return mainApi .delete(`/metrics/${id}/sharing`, { data }) .then((res) => res.data); }; export const updateMetricShare = async ({ params, id }: { id: string; params: ShareUpdateRequest; }) => { return mainApi.put(`/metrics/${id}/sharing`, params).then((res) => res.data); };