package com.owrawww.controller;

import com.owrawww.service.BbsService;
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 org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequiredArgsConstructor
public class BbsController {

    private final BbsService bbsService;

    @RequestMapping(value = "/bbs/owrainfo", method = {RequestMethod.GET, RequestMethod.POST})
    public String bbsList(
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 1;
        int subGubun = 1;
        bbsService.getList(page, searchType, keyword, topCode, leftCode, subGubun)
                  .forEach(model::addAttribute);
        return "sub04_01";
    }

    @GetMapping("/bbs/owrainfo/view")
    public String bbsView(
            @RequestParam Long  id,
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 1;
        int subGubun = 1;
        bbsService.getDetail(id, topCode, leftCode, subGubun, page, searchType, keyword)
                  .forEach(model::addAttribute);
        return "sub04_01_view";
    }

    @RequestMapping(value = "/business/progress", method = {RequestMethod.GET, RequestMethod.POST})
    public String progressList(
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 2;
        int subGubun = 1;
        bbsService.getList(page, searchType, keyword, topCode, leftCode, subGubun)
                  .forEach(model::addAttribute);
        return "sub02_08";
    }

    @GetMapping("/business/progress/view")
    public String progressView(
            @RequestParam Long  id,
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 2;
        int subGubun = 1;
        bbsService.getDetail(id, topCode, leftCode, subGubun, page, searchType, keyword)
                  .forEach(model::addAttribute);
        return "sub02_08_view";
    }

    @RequestMapping(value = "/bbs/press", method = {RequestMethod.GET, RequestMethod.POST})
    public String pressList(
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 4;
        int subGubun = 1;
        bbsService.getList(page, searchType, keyword, topCode, leftCode, subGubun)
                  .forEach(model::addAttribute);
        return "sub04_03";
    }

    @GetMapping("/bbs/press/view")
    public String pressView(
            @RequestParam Long  id,
            @RequestParam(defaultValue = "1")   int    page,
            @RequestParam(defaultValue = "all") String searchType,
            @RequestParam(defaultValue = "")    String keyword,
            Model model) {
        int topCode = 1;
        int leftCode = 4;
        int subGubun = 1;
        bbsService.getDetail(id, topCode, leftCode, subGubun, page, searchType, keyword)
                  .forEach(model::addAttribute);
        return "sub04_03_view";
    }
}