package com.jwipc.finance.controller.rest;

import com.jwipc.finance.dto.CustomsDeclarationDetailDTO;
import com.jwipc.finance.logic.CustomsDeclarationDetailLogic;
import com.jwipc.finance.model.query.CustomsDeclarationQuery;
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 + "/customs/declaration/detail/rest")
@RequiredArgsConstructor
public class CustomsDeclarationDetailRestController {
    private final CustomsDeclarationDetailLogic customsDeclarationDetailLogic;
    /**
     * 列表
     * @param mainId
     */
    @RequestMapping("/getDetailListByMainId")
    public PageView getDetailListByMainId(Long mainId) {
        return customsDeclarationDetailLogic.getPageDetailListByMainId(mainId);
    }

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

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

    @PostMapping("/provide/detail/byPaymentMatchingId")
    public ResponseEntity provideDetailByPaymentMatchingId(Long paymentMatchingId){
        return ResponseEntity.ok(customsDeclarationDetailLogic.provideDetailByPaymentMatchingId(paymentMatchingId));
    }
}
