package jnpf.cultivate.v2.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.cultivate.mapper.FtbCultivateCommonSettingGlobalMapper;
import jnpf.cultivate.v2.service.V2CultivateCommonSettingGlobalService;
import jnpf.model.cultivate.dto.FtbCultivateCommonSettingGlobalDTO;
import jnpf.model.cultivate.po.FtbCultivateCommonSettingGlobal;
import jnpf.model.cultivate.vo.FtbCultivateCommonSettingGlobalVO;
import jnpf.util.UserProvider;
import org.springframework.stereotype.Service;

/**
 * 培训通用配置 服务实现类
 *
 * @author xgl
 * @date 2026/02/11
 */
@Service
public class FtbCultivateCommonSettingGlobalServiceImpl
        extends ServiceImpl<FtbCultivateCommonSettingGlobalMapper, FtbCultivateCommonSettingGlobal>
        implements V2CultivateCommonSettingGlobalService {

    /**
     * 获取培训通用配置信息
     *
     * @return {@link FtbCultivateCommonSettingGlobalVO}
     */
    @Override
    public FtbCultivateCommonSettingGlobalVO getInfo() {
        // 查询唯一的配置记录，如果没有则返回null
        FtbCultivateCommonSettingGlobal entity = baseMapper.selectById("1");
        return convertFtbCultivateCommonSettingGlobalVO(entity);
    }

    /**
     * 转换为VO
     *
     * @param entity 实体
     * @return {@link FtbCultivateCommonSettingGlobalVO}
     */
    private FtbCultivateCommonSettingGlobalVO convertFtbCultivateCommonSettingGlobalVO(FtbCultivateCommonSettingGlobal entity) {
        FtbCultivateCommonSettingGlobalVO vo = new FtbCultivateCommonSettingGlobalVO();
        vo.setId(entity.getId());
        vo.setWatermark(entity.getWatermark());
        vo.setScreenshot(entity.getScreenshot());
        vo.setAttachmentsRule(entity.getAttachmentsRule());
        return vo;
    }

    /**
     * 提交培训通用配置
     *
     * @param dto 配置信息
     */
    @Override
    public void update(FtbCultivateCommonSettingGlobalDTO dto) {
        this.updateById(dto.convert(UserProvider.getLoginUserId()));
    }
}