import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  ContractForm,
  ContractQuery,
  ContractVO,
  ContractActivateForm,
  ContractRefundForm,
  ContractTransferForm
} from './types';

// 查询合同列表
export function listContract(query: ContractQuery): AxiosPromise<ContractVO[]> {
  return request({
    url: '/edu/contract/list',
    method: 'get',
    params: query
  });
}

// 查询合同详细(含明细、赠送、流水)
export function getContract(id: number | string): AxiosPromise<ContractVO> {
  return request({
    url: '/edu/contract/' + id,
    method: 'get'
  });
}

// 新增合同(草稿态)
export function addContract(data: ContractForm) {
  return request({
    url: '/edu/contract',
    method: 'post',
    data: data
  });
}

// 修改合同(仅草稿态)
export function updateContract(data: ContractForm) {
  return request({
    url: '/edu/contract',
    method: 'put',
    data: data
  });
}

// 删除合同(仅草稿/作废态)
export function delContract(id: string | number | (string | number)[]) {
  return request({
    url: '/edu/contract/' + id,
    method: 'delete'
  });
}

// 作废合同
export function voidContract(id: number | string) {
  return request({
    url: '/edu/contract/void/' + id,
    method: 'put'
  });
}

// 激活合同: 草稿/待生效 → 执行中
export function activateContract(data: ContractActivateForm) {
  return request({
    url: '/edu/contract/activate',
    method: 'put',
    data: data
  });
}

// 退费: 执行中 → 已退费
export function refundContract(data: ContractRefundForm) {
  return request({
    url: '/edu/contract/refund',
    method: 'put',
    data: data
  });
}

// 转课: 执行中 → 已转课
export function transferContract(data: ContractTransferForm) {
  return request({
    url: '/edu/contract/transfer',
    method: 'put',
    data: data
  });
}
