package com.jwipc.sys.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.sys.dto.BusinessAttachmentDTO;
import com.jwipc.sys.dto.BusinessAttachmentDeleteOrUpdateDTO;
import com.jwipc.sys.entity.BusinessAttachment;
import com.jwipc.sys.logic.BusinessAttachmentLogic;
import com.jwipc.sys.model.query.BusinessAttachmentQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

/**
 * <p>
 *
 * </p>
 *
 * @author Chen Tianshi
 * @since 2025/9/12 12:04
 */
@RestController
@RequestMapping(MODULE_ROOT + "/businessAttachment/rest/")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class BusinessAttachmentRestController {
    private final BusinessAttachmentLogic businessAttachmentLogic;

    /**
     * 附件对话框查询
     * @param query ID
     * @return 附件数据
     */
    @RequestMapping("businessAttachmentList")
    public PageView list(BusinessAttachmentQuery query) {
        return businessAttachmentLogic.list(query);
    }

    @RequestMapping("businessAttachmentListNoPage")
    public PageView listNoPage(BusinessAttachmentQuery query) {
        return businessAttachmentLogic.listNoPage(query);
    }

    @RequestMapping("businessAttachmentListNoPageByCodes")
    public PageView listByCodes(BusinessAttachmentQuery query) {
        return businessAttachmentLogic.listNoPageByCodes(query);
    }

    /**
     * 保存上传附件
     * @param saveList 上传文件的数据
     * @return 处理结果
     */
    @PostMapping("save")
    public ResponseEntity<List<BusinessAttachment>> save(@RequestBody List<BusinessAttachmentDTO> saveList) {
        List<BusinessAttachment> savedAttachments = businessAttachmentLogic.saveAttachment(saveList);
        return ResponseEntity.ok(savedAttachments);
    }

    /**
     * 删除附件
     * @param deleteDTO 删除附件的ID、删除备注
     * @return 处理结果
     */
    @PostMapping("delete")
    public ResponseEntity<Boolean> delete(BusinessAttachmentDeleteOrUpdateDTO deleteDTO) {
        businessAttachmentLogic.deleteAttachment(deleteDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("deleteCheck")
    public ResponseEntity<Boolean> deleteCheck(BusinessAttachmentDeleteOrUpdateDTO deleteDTO) {
        businessAttachmentLogic.deleteCheck(deleteDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加备注
     * @param updateDTO 备注附件的ID、备注
     * @return 处理结果
     */
    @PostMapping("remark")
    public ResponseEntity<Boolean> remark(BusinessAttachmentDeleteOrUpdateDTO updateDTO) {
        businessAttachmentLogic.remarkAttachment(updateDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据文件ID 查询是否被开票申请引用
     * @param
     * @return 处理结果
     */
    @PostMapping("findInvoiceByFileId")
    public List<String> findInvoiceByFileId(Long id) {
        return businessAttachmentLogic.findInvoiceByFileId(id);
    }
}
