package com.yuchen.saas.park.service.service.approve.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuchen.saas.park.api.entity.approve.SaasGenericConfig;
import com.yuchen.saas.park.api.enums.approve.ApproveConfigGroupEnum;
import com.yuchen.saas.park.service.mapper.approve.SaasGenericConfigMapper;
import com.yuchen.saas.park.service.service.approve.ISaasGenericConfigService;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: 洪铭铭
 * @time: 2024/5/27 16:55
 */
@Slf4j
@Service
public class SaasGenericConfigServiceImpl extends BaseServiceImpl<SaasGenericConfigMapper, SaasGenericConfig>
        implements ISaasGenericConfigService {
    /**
     * @description:
     * @param
     * @return: java.util.List<com.yuchen.saas.park.api.entity.approve.SaasGenericConfig>
     * @author: 洪铭铭
     * @time: 2024/5/27 17:09
     */
    @Override
    public List<SaasGenericConfig> getAll() {
        List<SaasGenericConfig> saasGenericConfigList = this.list();

        for (SaasGenericConfig config : saasGenericConfigList) {
            for (ApproveConfigGroupEnum group : ApproveConfigGroupEnum.values()) {
                if (Func.equals(config.getConfigGroupName(), String.valueOf(group.getValue())) ) {
                    config.setConfigGroupName(group.getDesc());

                }
            }

        }

        return saasGenericConfigList;
    }
    /**
     * @description:
     * @param param
     * @return: com.yuchen.saas.park.api.entity.approve.SaasGenericConfig
     * @author: 洪铭铭
     * @time: 2024/6/3 16:28
     */
    @Override
    public SaasGenericConfig getConfigValue(String param) {
        LambdaQueryWrapper<SaasGenericConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SaasGenericConfig::getConfigGroupName, param);
        SaasGenericConfig saasGenericConfig = this.getOne(queryWrapper);
        return saasGenericConfig;
    }
}
