package com.jwipc.message.controller;

import cn.hutool.core.util.ObjectUtil;
import com.jwipc.message.dto.MessageCenterDTO;
import com.jwipc.message.logic.MessageAddresseeLogic;
import com.jwipc.message.logic.MessageCenterLogic;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;

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

/**
 * <p>
 * 我发起的 前端控制器
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-07-03
 */
@Controller
@RequestMapping(MODULE_ROOT + "/launch")
@RequiredArgsConstructor
public class MessageLaunchPageController {
    private final MessageCenterLogic messageCenterLogic;
    @GetMapping("/index")
    public String index(Model model) {
        return MODULE_ROOT + "/launch/list";
    }

    @GetMapping("/detail")
    public String detail(Model model, Long id,Integer optType) {
        MessageCenterDTO messageCenterDTO = new MessageCenterDTO();
        if (ObjectUtil.isNotNull(id)){
            messageCenterDTO = messageCenterLogic.getById(id);
        }else {
            messageCenterDTO.setIsSupplierReply(0);
            messageCenterDTO.setIsSupplierConfirm(0);
            messageCenterDTO.setIsSupplierFile(0);
        }
        model.addAttribute("data", messageCenterDTO);
        model.addAttribute("optType", optType);
        return MODULE_ROOT + "/launch/detail";
    }

    @GetMapping("/look")
    public String look(Model model, Long id) {
        MessageCenterDTO messageCenterDTO = new MessageCenterDTO();
        if (ObjectUtil.isNotNull(id)){
            messageCenterDTO = messageCenterLogic.getById(id);
        }
        model.addAttribute("data", messageCenterDTO);
        return MODULE_ROOT + "/launch/look";
    }

    @GetMapping("/userSelect")
    public String userSelect(Model model, Integer type) {
        model.addAttribute("type", type);
        return MODULE_ROOT + "/user_select";
    }
}
