import request from '@/utils/request';
import type { SystemReleaseResponse, SystemReleaseRequest, SystemReleaseQuery } from './types';
import { Page } from '@/types/base';

const BASE_URL = '/api/v1/system-release';

/**
 * 获取系统版本列表(分页)
 */
export const getSystemReleaseList = (params?: SystemReleaseQuery) =>
    request.get<Page<SystemReleaseResponse>>(`${BASE_URL}/page`, { params });

/**
 * 获取所有系统版本列表(不分页)
 */
export const getAllSystemReleases = () =>
    request.get<SystemReleaseResponse[]>(`${BASE_URL}/list`);

/**
 * 根据条件查询系统版本列表(不分页)
 */
export const querySystemReleases = (params?: SystemReleaseQuery) =>
    request.get<SystemReleaseResponse[]>(`${BASE_URL}/query`, { params });

/**
 * 获取系统版本详情
 */
export const getSystemRelease = (id: number) =>
    request.get<SystemReleaseResponse>(`${BASE_URL}/${id}`);

/**
 * 创建系统版本
 */
export const createSystemRelease = (data: SystemReleaseRequest) =>
    request.post<SystemReleaseResponse>(BASE_URL, data);

/**
 * 更新系统版本
 */
export const updateSystemRelease = (id: number, data: SystemReleaseRequest) =>
    request.put<SystemReleaseResponse>(`${BASE_URL}/${id}`, data);

/**
 * 删除系统版本
 */
export const deleteSystemRelease = (id: number) =>
    request.delete<void>(`${BASE_URL}/${id}`);

/**
 * 批量处理系统版本
 */
export const batchSystemReleases = (data: SystemReleaseRequest[]) =>
    request.post<void>(`${BASE_URL}/batch`, data);

/**
 * 获取未通知的系统版本列表
 */
export const getUnnotifiedReleases = () =>
    request.get<SystemReleaseResponse[]>(`${BASE_URL}/unnotified`);

/**
 * 标记为已通知
 */
export const markAsNotified = (id: number) =>
    request.put<void>(`${BASE_URL}/${id}/notify`);

/**
 * 获取指定模块的最新版本
 */
export const getLatestRelease = (module: string) =>
    request.get<SystemReleaseResponse>(`${BASE_URL}/latest/${module}`);
