import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { JenkinsTaskVO, JenkinsTaskForm, JenkinsTaskQuery } from '@/api/personal/jenkinsTask/types';

/**
 * 查询Jenkins任务列表
 * @param query
 * @returns {*}
 */

export const listJenkinsTask = (query?: JenkinsTaskQuery): AxiosPromise<JenkinsTaskVO[]> => {
  return request({
    url: '/personal/jenkinsTask/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询Jenkins任务详细
 * @param taskId
 */
export const getJenkinsTask = (taskId: string | number): AxiosPromise<JenkinsTaskVO> => {
  return request({
    url: '/personal/jenkinsTask/' + taskId,
    method: 'get'
  });
};

/**
 * 新增Jenkins任务
 * @param data
 */
export const addJenkinsTask = (data: JenkinsTaskForm) => {
  return request({
    url: '/personal/jenkinsTask',
    method: 'post',
    data: data
  });
};

/**
 * 修改Jenkins任务
 * @param data
 */
export const updateJenkinsTask = (data: JenkinsTaskForm) => {
  return request({
    url: '/personal/jenkinsTask',
    method: 'put',
    data: data
  });
};

/**
 * 删除Jenkins任务
 * @param taskId
 */
export const delJenkinsTask = (taskId: string | number | Array<string | number>) => {
  return request({
    url: '/personal/jenkinsTask/' + taskId,
    method: 'delete'
  });
};

/**
 * 查询Jenkins任务详细
 * @param taskId
 */
export const runJenkinsTask = (taskId: string | number) => {
  return request({
    url: '/personal/jenkinsTask/run/' + taskId,
    method: 'get'
  });
};

export const viewJenkinsTask = (name: string | number) => {
  return request({
    url: '/personal/jenkinsTask/view/' + name,
    method: 'get'
  });
};
