package com.dbnt.faisp.controller;

import com.dbnt.faisp.fpiMgt.monthPlan.MonthPlanService;
import com.dbnt.faisp.fpiMgt.monthPlan.model.BoardPlan;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/fpiMgt")
public class FpiMgtController { // 외사경찰견문관리
  private final MonthPlanService monthPlanService;

  @GetMapping("/monthPlanPage")
  public ModelAndView monthPlanPage(@AuthenticationPrincipal UserInfo loginUser, BoardPlan boardPlan){
    ModelAndView mav = new ModelAndView("igActivities/fpiMgt/monthPlan/monthPlan");
    mav.addObject("loginUser", loginUser);
    boardPlan.setQueryInfo();
    mav.addObject("monthPlanList", null);
    boardPlan.setContentCnt(0);
    boardPlan.setPaginationInfo();
    mav.addObject("searchParams", boardPlan);
    return mav;
  }

  @GetMapping("/planEditModal")
  public ModelAndView planEditModal(@AuthenticationPrincipal UserInfo loginUser, BoardPlan boardPlan){
    ModelAndView mav = new ModelAndView("igActivities/fpiMgt/monthPlan/planEditModal");
    if(boardPlan.getPlanKey()!=null){
      boardPlan = monthPlanService.selectBoardPlan(boardPlan.getPlanKey());
    }else{
      boardPlan.setWrtOrgan(loginUser.getOgCd());
      boardPlan.setWrtNm(loginUser.getUserNm());
      boardPlan.setWrtDt(LocalDateTime.now());
    }
    mav.addObject("plan", boardPlan);
    return mav;
  }

  @PostMapping("/savePlan")
  public Integer savePlan(BoardPlan boardPlan,
                          @RequestParam(value = "planInfos", required = false) List<String> planInfos,
                          @RequestParam(value = "detailPlanInfos", required = false)List<String> detailPlanInfos){
    return 0;
  }
}
