package cn.reghao.bnt.web.admin.service;

import cn.reghao.bnt.web.admin.db.repository.SiteOptionRepo;
import cn.reghao.bnt.web.admin.model.po.SiteOption;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author reghao
 * @date 2025-06-19 09:37:49
 */
@Service
public class SiteOptionService {
    private final SiteOptionRepo siteOptionRepo;

    public SiteOptionService(SiteOptionRepo siteOptionRepo) {
        this.siteOptionRepo = siteOptionRepo;
    }

    @CacheEvict(cacheNames = "siteOptions", key = "#newSiteOption.getPropKey()")
    public void updateSiteOption(SiteOption newSiteOption) {
        siteOptionRepo.updateSiteOption(newSiteOption);
    }

    public Page<SiteOption> getAll() {
        return siteOptionRepo.getAll();
    }

    public String getDevopsWebhook() {
        String propKey = "site.devops.webhook_name";
        String propValue = siteOptionRepo.getPropValue(propKey);
        return propValue;
    }
}
