/*
 *    Copyright (c) 2018-2025, cyweb All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 */

import request from '/@/utils/request';

/**
 * 获取招标文件列表（含历史版本）
 * @param applyId 采购申请ID
 */
export function getDocList(applyId: number | string) {
	return request({
		url: '/purchase/purchasingdoc/list/' + applyId,
		method: 'get'
	});
}

/**
 * 上传招标文件（招标代理）
 * @param data 文件信息
 */
export function uploadDoc(data: any) {
	return request({
		url: '/purchase/purchasingdoc/upload',
		method: 'post',
		data
	});
}

/**
 * 重新上传招标文件
 * @param data 文件信息
 */
export function reuploadDoc(data: any) {
	return request({
		url: '/purchase/purchasingdoc/reupload',
		method: 'post',
		data
	});
}

/**
 * 获取招标文件下载地址
 * @param id 招标文件ID
 */
export function getDocDownloadUrl(id: number | string) {
	return `/purchase/purchasingdoc/download/${id}`;
}

/**
 * 下载招标文件（返回blob）
 * @param id 招标文件ID
 */
export function downloadDocById(id: number | string) {
	return request({
		url: `/purchase/purchasingdoc/download/${id}`,
		method: 'get',
		responseType: 'blob'
	});
}

/**
 * 确认无误
 * @param data 审核信息
 */
export function confirmDoc(data: any) {
	return request({
		url: '/purchase/purchasingdoc/confirm',
		method: 'post',
		data
	});
}

/**
 * 退回修改
 * @param data 审核信息
 */
export function returnDoc(data: any) {
	return request({
		url: '/purchase/purchasingdoc/return',
		method: 'post',
		data
	});
}

/**
 * 确认流程结束
 * @param applyId 采购申请ID
 */
export function completeDoc(applyId: number | string) {
	return request({
		url: '/purchase/purchasingdoc/complete',
		method: 'post',
		params: { applyId }
	});
}

/**
 * 获取审核记录
 * @param applyId 采购申请ID
 */
export function getAuditRecords(applyId: number | string) {
	return request({
		url: '/purchase/purchasingdoc/audit-records/' + applyId,
		method: 'get'
	});
}

/**
 * 获取待审核列表
 * @param params 分页参数
 */
export function getMyPending(params?: any) {
	return request({
		url: '/purchase/purchasingdoc/my-pending',
		method: 'get',
		params
	});
}

/**
 * 获取可执行操作
 * @param applyId 采购申请ID
 */
export function getAvailableActions(applyId: number | string) {
	return request({
		url: '/purchase/purchasingdoc/actions/' + applyId,
		method: 'get'
	});
}

/**
 * 审核人员分页查询招标文件列表（只查询有招标文件记录的申请）
 * @param params 分页和筛选参数
 */
export function getDocAuditPage(params?: any) {
	return request({
		url: '/purchase/purchasingdoc/audit/page',
		method: 'get',
		params
	});
}

/**
 * 保存草稿（招标代理）
 * @param data 文件信息
 */
export function saveDraft(data: any) {
	return request({
		url: '/purchase/purchasingdoc/save-draft',
		method: 'post',
		data
	});
}

/**
 * 提交草稿（招标代理）
 * @param data 文件信息
 */
export function submitDraft(data: any) {
	return request({
		url: '/purchase/purchasingdoc/submit-draft',
		method: 'post',
		data
	});
}

/**
 * 补充上传（资产管理处）
 * @param data 文件信息（含fileRemark）
 */
export function supplyUpload(data: any) {
	return request({
		url: '/purchase/purchasingdoc/supply-upload',
		method: 'post',
		data
	});
}

/**
 * 提交至需求部门（资产管理处）
 * @param data 审核信息
 */
export function submitToDept(data: any) {
	return request({
		url: '/purchase/purchasingdoc/submit-to-dept',
		method: 'post',
		data
	});
}

/**
 * 提交至内审部门（资产管理处）
 * @param data 审核信息
 */
export function submitToAudit(data: any) {
	return request({
		url: '/purchase/purchasingdoc/submit-to-audit',
		method: 'post',
		data
	});
}

/**
 * 提交至资产管理处（需求部门/内审部门）
 * @param data 审核信息
 */
export function submitToAsset(data: any) {
	return request({
		url: '/purchase/purchasingdoc/submit-to-asset',
		method: 'post',
		data
	});
}