package me.qwq.doghouse.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import me.qwq.doghouse.controller.common.BaseController;
import me.qwq.doghouse.entity.config.SiteConfig;
import me.qwq.doghouse.pojo.dto.R;
import me.qwq.doghouse.service.ThemeService;

@Controller
@RequestMapping("/admin/v2/themes")
public class ThemeController extends BaseController {

    @Autowired
    SiteConfig siteConfig;
    
    @Autowired
    ThemeService themeService;
    
    @GetMapping({"", "/", "/index"})
    public String index() {
        return "admin/themes/index";
    }

    @ResponseBody
    @PostMapping("/setTheme")
    public R<?> setTheme(String identity) {
        return R.judge(siteConfig.setThemeIdentity(identity).saveOrUpdate());
    }
    
    @ResponseBody
    @PostMapping("/extractTheme")
    public R<?> extractTheme(String identity) {
        return R.judge(() -> themeService.copyInternalToExternal(identity));
    }
    
    

}
