package kr.iotdoor.boot.web;

import kr.iotdoor.boot.service.ContactSubmissionService;
import kr.iotdoor.boot.service.PortfolioService;
import kr.iotdoor.boot.service.UserManagementService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AdminController {

    private final ContactSubmissionService contactSubmissionService;
    private final PortfolioService portfolioService;
    private final UserManagementService userManagementService;

    public AdminController(
        ContactSubmissionService contactSubmissionService,
        PortfolioService portfolioService,
        UserManagementService userManagementService
    ) {
        this.contactSubmissionService = contactSubmissionService;
        this.portfolioService = portfolioService;
        this.userManagementService = userManagementService;
    }

    @GetMapping({"/mfuc/index.do", "/mngr/index.do"})
    public String dashboard(Model model) {
        model.addAttribute("recentContacts", contactSubmissionService.recentSubmissions(10));
        model.addAttribute("recentPortfolios", portfolioService.getAdminPortfolioItems().stream().limit(5).toList());
        model.addAttribute("contactCount", contactSubmissionService.count());
        model.addAttribute("portfolioCount", portfolioService.count());
        model.addAttribute("activeUserCount", userManagementService.countActiveUsers());
        model.addAttribute("adminUserCount", userManagementService.countAdminUsers());
        model.addAttribute("adminMenu", "dashboard");
        model.addAttribute("pageTitle", "Dashboard");
        model.addAttribute("pageDescription", "관리자, 포트폴리오, 문의 현황을 한 화면에서 확인합니다.");
        return "kr/iotdoor/boot/admin/dashboard";
    }

    @GetMapping("/mfuc/contact/list.do")
    public String contactList(Model model) {
        model.addAttribute("contacts", contactSubmissionService.findAll());
        model.addAttribute("adminMenu", "contact");
        model.addAttribute("pageTitle", "문의 내역");
        model.addAttribute("pageDescription", "홈페이지 문의 접수 내역과 연락처 정보를 확인합니다.");
        return "kr/iotdoor/boot/admin/contact/list";
    }
}
