import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ConfigVO, ConfigForm, ConfigQuery } from '@/api/system/business/config/types';
import { StructuresVO } from '@/api/system/business/structures/types';

/**
 * 查询排期配置：用于保存具体的排期实例配置列表
 * @param query
 * @returns {*}
 */

export const listConfig = (query?: ConfigQuery): AxiosPromise<ConfigVO[]> => {
  return request({
    url: '/business/config/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询排期配置：用于保存具体的排期实例配置详细
 * @param id
 */
export const getConfig = (id: string | number): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/config/' + id,
    method: 'get'
  });
};

/**
 * 新增排期配置：用于保存具体的排期实例配置
 * @param data
 */
export const addConfig = (data: ConfigForm) => {
  return request({
    url: '/business/config',
    method: 'post',
    data: data
  });
};

/**
 * 修改排期配置：用于保存具体的排期实例配置
 * @param data
 */
export const updateConfig = (data: ConfigForm) => {
  return request({
    url: '/business/config',
    method: 'put',
    data: data
  });
};

/**
 * 删除排期配置：用于保存具体的排期实例配置
 * @param id
 */
export const delConfig = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/config/' + id,
    method: 'delete'
  });
};

/**
 * 查询所有模版
 */
export const selectTemplateTourList = (): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/tournamentsTemplate/selectTemplateTourList',
    method: 'get'
  });
};

/**
 * 新增排期配置：用于保存具体的排期实例配置
 * @param data
 */
export const createSchedule = (data: ConfigForm) => {
  return request({
    url: '/business/config/createSchedule',
    method: 'post',
    data: data
  });
};

/**
 * 修改排期配置：用于保存具体的排期实例配置
 * @param data
 */
export const updateScheduleConfig = (data: ConfigForm) => {
  return request({
    url: '/business/config/updateScheduleConfig',
    method: 'post',
    data: data
  });
};

/**
 * 删除排期配置：用于保存具体的排期实例配置
 * @param id
 */
export const deleteScheduleConfig = (id: string | number): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/config/deleteScheduleConfig/' + id,
    method: 'delete'
  });
};

/**
 * 停止配置
 * @param id
 */
export const stopScheduleConfig = (id: string | number): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/config/stopScheduleConfig/' + id,
    method: 'post'
  });
};

/**
 * 开启配置
 * @param id
 */
export const startScheduleConfig = (id: string | number): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/config/startScheduleConfig/' + id,
    method: 'post'
  });
};

/**
 * 生成未来指定天数的数据
 * @param days 天数
 */
export const generateMatchesForNextDays = (days: number, configId: string | number): AxiosPromise<ConfigVO> => {
  return request({
    url: '/business/job/generateMatchesForNextDays',
    method: 'post',
    params: { days, configId } // 添加 configId 参数传递
  });
};
