import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ElderLeaveVO, ElderLeaveForm, ElderLeaveQuery } from '@/api/residenceService/elderLeave/types';

/**
 * 查询在住老人请假列表
 * @param query
 * @returns {*}
 */

export const listElderLeave = (query?: ElderLeaveQuery): AxiosPromise<ElderLeaveVO[]> => {
  return request({
    url: '/residential/elderLeave/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询在住老人请假详细
 * @param id
 */
export const getElderLeave = (id: string | number): AxiosPromise<ElderLeaveVO> => {
  return request({
    url: '/residential/elderLeave/' + id,
    method: 'get'
  });
};

/**
 * 新增在住老人请假
 * @param data
 */
export const addElderLeave = (data: ElderLeaveForm) => {
  return request({
    url: '/residential/elderLeave',
    method: 'post',
    data: data
  });
};

/**
 * 修改在住老人请假
 * @param data
 */
export const updateElderLeave = (data: ElderLeaveForm) => {
  return request({
    url: '/residential/elderLeave',
    method: 'put',
    data: data
  });
};

export const updateActualReturnApi = (data: ElderLeaveForm) => {
  return request({
    url: '/residential/elderLeave/actual-return',
    method: 'post',
    data: data
  });
};

export const confirmActualReturnApi = (data: ElderLeaveForm) => {
  return request({
    url: '/residential/elderLeave/actual-return',
    method: 'put',
    data: data
  });
};

/**
 * 删除在住老人请假
 * @param id
 */
export const delElderLeave = (id: string | number | Array<string | number>) => {
  return request({
    url: '/residential/elderLeave/' + id,
    method: 'delete'
  });
};

/**
 * 审批通过
 */
export const approveElderLeaveApi = (id: string) => {
  return request({
    url: '/residential/elderLeave/approve',
    method: 'put',
    data: { id }
  });
};

/**
 * 审批驳回
 */
export const rejectElderLeaveApi = (id: string) => {
  return request({
    url: '/residential/elderLeave/reject',
    method: 'put',
    data: { id }
  });
}
