package com.jwipc.supplier.controller.pc;

import com.jwipc.supplier.constant.ModuleConst;
import com.jwipc.supplier.dto.SupplierTemplateBaseDTO;
import com.jwipc.supplier.logic.SupplierTemplateLogic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.web.bind.annotation.RequestParam;

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

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Controller
@RequestMapping(MODULE_ROOT + "/template/page")
@RequiredArgsConstructor
@Slf4j
public class SupplierTemplatePageController {
    private final SupplierTemplateLogic supplierTemplateLogic;

    @GetMapping("index")
    public String index() {
        return ModuleConst.MODULE_ROOT + "/template/index";
    }

    @GetMapping("select/fields")
    public String selectFields() {
        return ModuleConst.MODULE_ROOT + "/template/select_fields";
    }

    @GetMapping("detail")
    public String detail(Model model,
                         @RequestParam(required = false, defaultValue = "0") Integer copyFlag,
                         @RequestParam(required = false, defaultValue = "0") Long id)
    {
        SupplierTemplateBaseDTO supplierTemplateBaseDTO = supplierTemplateLogic.getDetail(id);
        model.addAttribute("template", supplierTemplateBaseDTO);
        model.addAttribute("copyFlag", copyFlag);
        return ModuleConst.MODULE_ROOT + "/template/detail";
    }
}
