package com.jwipc.inquiry.controller.rest;

import com.jwipc.inquiry.constant.ModuleConst;
import com.jwipc.inquiry.dto.InquiryTemplateDTO;
import com.jwipc.inquiry.dto.InquiryTemplateFieldDTO;
import com.jwipc.inquiry.logic.InquiryTemplateLogic;
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.*;

import java.util.List;

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

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

    /**
     * 下拉
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<InquiryTemplateDTO>> listAll(InquiryTemplateQuery query) {
        return ResponseEntity.ok(inquiryTemplateLogic.listAll(query));
    }

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

    /**
     * 根据模板编码和模板字段分组获取模板字段(查询模板字段用)
     * @param templateCode 模板编码
     * @param fieldGroup 模板字段分组；0-基础字段；1-基础扩展；2-阶梯报价；3-自定义扩展字段
     * @return 字段
     */
    @RequestMapping("/getFieldByTemplateCodeAndFieldGroup")
    public ResponseEntity<List<InquiryTemplateFieldDTO>> getFieldByTemplateCodeAndFieldGroup(String templateCode, Integer fieldGroup) {
        return ResponseEntity.ok(inquiryTemplateLogic.getFieldByTemplateCodeAndFieldGroup(templateCode,fieldGroup,null));
    }

    /**
     * 根据模板编码获取供应商显示和编辑字段
     * @param templateCode 模板编码
     * @return 字段
     */
    @RequestMapping("/getSupplierFieldByTemplateCode")
    public ResponseEntity<List<InquiryTemplateFieldDTO>> getSupplierFieldByTemplateCode(String templateCode) {
        return ResponseEntity.ok(inquiryTemplateLogic.getSupplierFieldByTemplateCode(templateCode));
    }

    /**
     * 根据模板编码获取定价显示字段
     * @param templateCode 模板编码
     * @return 字段
     */
    @RequestMapping("/getFixFieldByTemplateCode")
    public ResponseEntity<List<InquiryTemplateFieldDTO>> getFixFieldByTemplateCode(String templateCode) {
        return ResponseEntity.ok(inquiryTemplateLogic.getFixFieldByTemplateCode(templateCode));
    }

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

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

}
