package com.jwipc.inquiry.controller;


import cn.hutool.core.util.ObjectUtil;
import com.jwipc.inquiry.dto.InquiryCostTemplateDTO;
import com.jwipc.inquiry.logic.InquiryCostTemplateLogic;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.Objects;

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

/**
 * @author shenyang.ou
 * @date 2024/2/4 19:48
 * @desc 询价成本模板
 */
@Controller
@RequestMapping(MODULE_ROOT + "/cost/template")
@RequiredArgsConstructor
public class InquiryCostTemplatePageController {
    private final InquiryCostTemplateLogic inquiryCostTemplateLogic;

    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("userId", Objects.requireNonNull(LoginUtil.getCurrentUser()).getUserId());
        return MODULE_ROOT + "/template/cost/list";
    }

    @GetMapping("/detail")
    public String detail(Model model, Long id,Integer optType) {
        InquiryCostTemplateDTO inquiryCostTemplateDTO = new InquiryCostTemplateDTO();
        if (ObjectUtil.isNotNull(id)){
            inquiryCostTemplateDTO = inquiryCostTemplateLogic.getById(id);
            if (optType==2){
                inquiryCostTemplateDTO.setTemplateCode(null);
            }
        }
        model.addAttribute("data", inquiryCostTemplateDTO);
        return MODULE_ROOT + "/template/cost/detail";
    }
}
