package com.jwipc.finance.controller.rest;

import com.jwipc.finance.dto.PaymentNoticeDetailDTO;
import com.jwipc.finance.logic.PaymentNoticeDetailLogic;
import com.jwipc.finance.model.query.PaymentNoticeQuery;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

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

/**
 * <p>
 * 对账模块-报关单主表 前端控制器
 * </p>
 *
 * @author shenyang.ou
 * @since 2025-10-22
 */
@RestController
@RequestMapping(MODULE_ROOT + "/payment/notice/detail/rest")
@RequiredArgsConstructor
public class PaymentNoticeDetailRestController {
    private final PaymentNoticeDetailLogic paymentNoticeDetailLogic;
    /**
     * 列表
     * @param mainId
     */
    @RequestMapping("/getDetailListByMainId")
    public ResponseEntity<List<PaymentNoticeDetailDTO>> getDetailListByMainId(Long mainId) {
        return ResponseEntity.ok(paymentNoticeDetailLogic.getDetailListByMainId(mainId));
    }

    @PostMapping("/dialog/list")
    public PageView dialogList(PaymentNoticeQuery query){
        if (LoginUtil.isSupplier()){
            query.setSupplierCode(LoginUtil.getSupplierCode());
        }else {
            query.setUserId(LoginUtil.getUserId());
        }
        return paymentNoticeDetailLogic.findByPage(query);
    }

    @PostMapping("/create/noPage/list")
    public PageView createList(PaymentNoticeQuery query){
        return paymentNoticeDetailLogic.createNoPageList(query);
    }

    @PostMapping("/provide/detail/byCostMatchingId")
    public ResponseEntity provideDetailByCostMatchingId(Long costMatchingId){
        return ResponseEntity.ok(paymentNoticeDetailLogic.provideDetailByCostMatchingId(costMatchingId));
    }
}
