package kr.iotdoor.boot.web;

import kr.iotdoor.boot.service.ContactSubmissionService;
import kr.iotdoor.boot.service.MigrationCatalogService;
import kr.iotdoor.boot.service.PortfolioService;
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 MigrationCatalogService migrationCatalogService;
    private final PortfolioService portfolioService;

    public AdminController(
        ContactSubmissionService contactSubmissionService,
        MigrationCatalogService migrationCatalogService,
        PortfolioService portfolioService
    ) {
        this.contactSubmissionService = contactSubmissionService;
        this.migrationCatalogService = migrationCatalogService;
        this.portfolioService = portfolioService;
    }

    @GetMapping({"/mfuc/index.do", "/mngr/index.do"})
    public String dashboard(Model model) {
        model.addAttribute("recentContacts", contactSubmissionService.recentSubmissions(10));
        model.addAttribute("contactCount", contactSubmissionService.count());
        model.addAttribute("portfolioCount", portfolioService.count());
        model.addAttribute("migrationFeatures", migrationCatalogService.getFeatures());
        return "kr/iotdoor/boot/admin/dashboard";
    }

    @GetMapping("/mfuc/contact/list.do")
    public String contactList(Model model) {
        model.addAttribute("contacts", contactSubmissionService.findAll());
        return "kr/iotdoor/boot/admin/contact/list";
    }
}
