import { get, put, post } from '@/utils/request.js'

/**
 * 查询用工草稿详情
 * GET /api/v1/mp/drafts/{id}
 * @param {number} draftId
 */
export function getDraftDetail(draftId, options = {}) {
	return get(`/drafts/${draftId}`, {}, options)
}

/**
 * 更新用工草稿（仅 pending 可编辑，传需修改字段）
 * PUT /api/v1/mp/drafts/{id}
 * @param {number} draftId
 * @param {Object} data DraftUpdateRequest
 */
export function updateDraft(draftId, data = {}, options = {}) {
	return put(`/drafts/${draftId}`, data, options)
}

/**
 * 成本测算（方案对比）
 * GET /api/v1/mp/drafts/{id}/cost-comparison
 * 要求草稿 pending 且 missingFields 为空
 * @param {number} draftId
 */
export function getDraftCostComparison(draftId, options = {}) {
	return get(`/drafts/${draftId}/cost-comparison`, {}, options)
}

/**
 * 确认此方案
 * POST /api/v1/mp/drafts/{id}/confirm
 * 要求草稿 pending 且 missingFields 为空；生成正式订单并将草稿置为 confirmed
 * @param {number} draftId
 * @param {string} selectedSchemeCode 如 SCHEME_A / SCHEME_B
 */
export function confirmDraft(draftId, selectedSchemeCode, options = {}) {
	const code = selectedSchemeCode == null ? '' : String(selectedSchemeCode).trim()
	return post(
		`/drafts/${draftId}/confirm`,
		{
			selectedSchemeCode: code,
			// 兼容文档 / MCP 风格 snake_case（若 DTO 带 @JsonProperty）
			selected_scheme_code: code
		},
		options
	)
}
