package com.nailart.controller;

import com.nailart.dataobj.MainInfoDO;
import com.nailart.enums.RespCodeEnum;
import com.nailart.service.MainInfoService;
import com.nailart.service.impl.FileStorageServiceImpl;
import com.nailart.vo.RespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 主页信息控制类
 * @Classname MainInfoController
 * @Date 2025/7/27 23:16
 * @Created by 21616
 */
@RestController
@RequestMapping("/mainInfo")
public class MainInfoController {
    private final MainInfoService mainInfoService;
    private static final Logger logger = LoggerFactory.getLogger(MainInfoController.class);


    public MainInfoController(MainInfoService mainInfoService) {

        this.mainInfoService = mainInfoService;
    }

    @RequestMapping("/getMainInfo")
    public RespVO getMainInfo() {
        try {
            MainInfoDO mainInfo = mainInfoService.getMainInfo();
            return RespVO.success(mainInfo);
        } catch (Exception e) {
            logger.error("获取主页信息失败", e);
            return RespVO.error(RespCodeEnum.DATABASE_ERROR, RespCodeEnum.DATABASE_ERROR.getMessage());
        }
    }

    @RequestMapping("/updateMainInfo")
    public RespVO updateMainInfo(@RequestBody MainInfoDO mainInfoDO) {
        try {
            mainInfoService.updateMainInfo(mainInfoDO);
            return RespVO.success();
        } catch (Exception e) {
            logger.error("更新主信息失败", e);
            return RespVO.error(RespCodeEnum.DATABASE_ERROR, RespCodeEnum.DATABASE_ERROR.getMessage());
        }
    }
}
