package com.sckw.system.service;

import com.sckw.core.utils.BeanUtils;
import com.sckw.core.web.response.BaseResult;
import com.sckw.system.model.SysArticles;
import com.sckw.system.model.vo.res.SysArticlesResVo;
import com.sckw.system.repository.SysArticlesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 系统文件相关接口
 * @create :2026-01-07 16:41:00
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class KwsSysArticlesService {
    private final SysArticlesService sysArticlesService;
    public SysArticlesResVo getPrivacyPolicy(String privacyPolicy) {
        SysArticles article = sysArticlesService.getByArticleKey(privacyPolicy);
        if (article == null) {
            log.error("隐私协议内容不存在");
            return new SysArticlesResVo();
        }
        return SysArticlesResVo.builder()
                .id(article.getId())
                .articleKey(article.getArticleKey())
                .title(article.getTitle())
                .content(article.getContent())
                .version(article.getVersion())
                .build();
    }

    public SysArticlesResVo getServiceAgreement(String regAgreement) {
        SysArticles article = sysArticlesService.getByArticleKey(regAgreement);
        if (article == null) {
            log.error("服务协议内容不存在");
            return new SysArticlesResVo();
        }
       return SysArticlesResVo.builder()
                .id(article.getId())
                .articleKey(article.getArticleKey())
                .title(article.getTitle())
                .content(article.getContent())
                .version(article.getVersion())
                .build();
    }

    public SysArticlesResVo getByArticleKey(String articleKey) {
        SysArticles article = sysArticlesService.getByArticleKey(articleKey);

        if (article == null) {
            log.error("文章内容不存在");
            return new SysArticlesResVo();
        }

        return SysArticlesResVo.builder()
                .id(article.getId())
                .articleKey(article.getArticleKey())
                .title(article.getTitle())
                .content(article.getContent())
                .version(article.getVersion())
                .build();
    }
}
