import { http } from '@/lib/http.ts';

// get application version
export function getVersion() {
  return http.get('/api/application/version');
}

// update application to latest version
export function update() {
  return http.request({
    method: 'post',
    url: '/api/application/update',
    timeout: 15 * 60 * 1000
  });
}

// enable/disable preview updates
export function setPreviewUpdates(enable: boolean) {
  const data = {
    enable
  };
  return http.post('/api/application/preview', data);
}

// get preview updates state
export function getPreviewUpdates() {
  return http.get('/api/application/preview');
}

// update server binary
export function updateServer(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return http.request({
    method: 'post',
    url: '/api/application/update/server',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// update web resources
export function updateWeb(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return http.request({
    method: 'post',
    url: '/api/application/update/web',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

