package com.jwipc.inquiry.controller.rest;

import com.jwipc.inquiry.constant.ModuleConst;
import com.jwipc.inquiry.dto.InquiryCostTemplateDTO;
import com.jwipc.inquiry.dto.InquiryTemplateDTO;
import com.jwipc.inquiry.dto.InquiryTemplateFieldDTO;
import com.jwipc.inquiry.logic.InquiryCostTemplateLogic;
import com.jwipc.inquiry.logic.InquiryTemplateLogic;
import com.jwipc.inquiry.model.query.InquiryCostTemplateQuery;
import com.jwipc.inquiry.model.query.InquiryTemplateQuery;
import com.jwipc.page.PageView;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/2/4 19:48
 * @desc
 */
@RestController
@RequestMapping(ModuleConst.MODULE_ROOT + "/cost/template/rest")
@RequiredArgsConstructor
public class InquiryCostTemplateRestController {
    private final InquiryCostTemplateLogic inquiryCostTemplateLogic;

    /**
     * 列表
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(InquiryCostTemplateQuery query) {
        return inquiryCostTemplateLogic.findByPage(query);
    }

    /**
     * 列表
     * @param query
     * @return
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<InquiryCostTemplateDTO>> listAll(InquiryCostTemplateQuery query) {
        return ResponseEntity.ok(inquiryCostTemplateLogic.listAll(query));
    }

    /**
     * 根据采购组编码获取成本模板且包含全部采购组
     * @param purchaseGroupCode 采购组编码
     */
    @RequestMapping("/getAllListByPurchaseGroupCode")
    public ResponseEntity<List<InquiryCostTemplateDTO>> getAllListByPurchaseGroupCode(String purchaseGroupCode) {
        return ResponseEntity.ok(inquiryCostTemplateLogic.getAllListByPurchaseGroupCode(purchaseGroupCode));
    }

    /**
     * 保存更新
     *
     * @param param 参数
     */
    @PostMapping("/saveOrUpdate")
    public ResponseEntity saveOrUpdate(@RequestBody InquiryCostTemplateDTO param) {
        inquiryCostTemplateLogic.saveOrUpdate(param);
        return ResponseEntity.ok(true);
    }

    /**
     * 逻辑删除
     *
     * @param id 参数
     */
    @PostMapping("/updateDeleteFlag")
    public ResponseEntity updateDeleteFlag(Long id) {
        inquiryCostTemplateLogic.updateDeleteFlag(id);
        return ResponseEntity.ok(true);
    }

}
