package com.schisandra.system.domain.service.impl;


import com.schisandra.system.common.enums.IsDeletedFlagEnum;
import com.schisandra.system.domain.convert.SchisandraSysConfigBOConverter;
import com.schisandra.system.domain.bo.SchisandraSysConfigBO;
import com.schisandra.system.domain.service.SchisandraSysConfigDomainService;
import com.schisandra.system.infra.basic.entity.SchisandraSysConfig;
import com.schisandra.system.infra.basic.service.SchisandraSysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *  领域service实现了
 *
 * @author landaiqing
 * @since 2024-05-11 22:45:55
 */
@Service
@Slf4j
public class SchisandraSysConfigDomainServiceImpl implements SchisandraSysConfigDomainService {

    @Resource
    private SchisandraSysConfigService schisandraSysConfigService;

    @Override
    public Boolean add(SchisandraSysConfigBO schisandraSysConfigBO) {
        SchisandraSysConfig schisandraSysConfig = SchisandraSysConfigBOConverter.INSTANCE.convertBOToEntity(schisandraSysConfigBO);
        schisandraSysConfig.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return schisandraSysConfigService.insert(schisandraSysConfig) > 0;
    }

    @Override
    public Boolean update(SchisandraSysConfigBO schisandraSysConfigBO) {
        SchisandraSysConfig schisandraSysConfig = SchisandraSysConfigBOConverter.INSTANCE.convertBOToEntity(schisandraSysConfigBO);
        return schisandraSysConfigService.update(schisandraSysConfig) > 0;
    }

    @Override
    public Boolean delete(SchisandraSysConfigBO schisandraSysConfigBO) {
        SchisandraSysConfig schisandraSysConfig = new SchisandraSysConfig();
        schisandraSysConfig.setId(schisandraSysConfigBO.getId());
        schisandraSysConfig.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        return schisandraSysConfigService.update(schisandraSysConfig) > 0;
    }

    @Override
    public SchisandraSysConfigBO getConfigByKey(String key) {
       SchisandraSysConfig schisandraSysConfig= schisandraSysConfigService.getConfigByKey(key);
        SchisandraSysConfigBO schisandraSysConfigBO = SchisandraSysConfigBOConverter.INSTANCE.convertEntityToBO(schisandraSysConfig);
        if (schisandraSysConfigBO == null){
           return null;
        }
        return schisandraSysConfigBO;
    }

}
