package org.springblade.modules.order.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.modules.order.pojo.dto.OrderLetterDTO;
import org.springblade.modules.order.pojo.entity.OperationOrderLetterEntity;
import org.springblade.modules.order.service.impl.OperationOrderLetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("sf/operationOrderLetter")
@Tag(name = "工单公函表", description = "工单公函表")
public class OperationOrderLetterController extends BladeController {

	@Autowired
	private OperationOrderLetterService operationOrderLetterService;
	/**
	 * 上传/修改 公函
	 */
	@PostMapping("/saveLetter")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "上传/修改 公函", description  = "传入")
	public R saveLetter(@Valid @RequestBody OrderLetterDTO orderLetterDTO) {
		return R.status(operationOrderLetterService.saveLetter(orderLetterDTO));
	}

	/**
	 * 删除公函
	 */
	@GetMapping(value = "/deleteLetter")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "删除公函", description  = "传入id")
	public R deleteLetter(@Parameter(name = "公函id", required = true) @RequestParam String id){
		return R.status(operationOrderLetterService.deleteLetter(id));
	}

	/**
	 * 获取工单的公函记录
	 */
	@GetMapping(value = "/getOrderLetterList")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "获取工单的公函记录", description  = "传入工单id")
	public R<List<OperationOrderLetterEntity>> getOrderLetterList(@Parameter(name = "orderId工单id", required = true) @RequestParam String orderId){
		List<OperationOrderLetterEntity> list =operationOrderLetterService.getOrderLetterList(orderId);
		return R.data(list);
	}
}
