package com.jwipc.sys.controller.pc;

import com.jwipc.sys.dto.KingdeeInvoiceCloudImageDTO;
import com.jwipc.sys.logic.KingdeeImageLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 *  金蝶发票云接口代理
 * </p>
 *
 * @author Chen Tianshi
 * @since 2025/9/24 14:54
 */
@RestController
@RequestMapping(MODULE_ROOT + "/kingdeeImage/rest/")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class KingdeeImageRestController {

    private final KingdeeImageLogic kingdeeImageLogic;

    /**
     * 推送影像文件到影像系统
     * @param pushDTO 业务附件明细、单据编码
     */
    @PostMapping("pushImage")
    public ResponseEntity<Boolean> pushImage(@RequestBody KingdeeInvoiceCloudImageDTO pushDTO) {
        kingdeeImageLogic.pushImage(pushDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除影像（整单删除）
     * @param deleteDTO 业务附件明细、单据编码、删除原因
     */
    @PostMapping("deleteAllImage")
    public ResponseEntity<Boolean> deleteAllImage(@RequestBody KingdeeInvoiceCloudImageDTO deleteDTO) {
        kingdeeImageLogic.deleteAllImage(deleteDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除影像
     * @param deleteDTO 单据编码、影像编码
     */
    @PostMapping("deleteImage")
    public ResponseEntity<Boolean> deleteImage(@RequestBody KingdeeInvoiceCloudImageDTO deleteDTO) {
        kingdeeImageLogic.deleteImage(deleteDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取影像查看页面地址
     * @param imageCode 影像编码
     * @return 影像查看页面地址
     */
    @GetMapping("getImageViewPath")
    public ResponseEntity<String> getImageViewPath(@RequestParam String imageCode) {
        String path = kingdeeImageLogic.getImageViewPath(imageCode);
        return ResponseEntity.ok(path);
    }
}
