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


import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
import com.schisandra.oss.domain.convert.SchisandraOssMinioBOConverter;
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssMinio;
import com.schisandra.oss.infra.basic.service.SchisandraOssMinioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 领域service实现了
 *
 * @author landaiqing
 * @since 2024-05-14 19:47:04
 */
@Service
@Slf4j
public class SchisandraOssMinioDomainServiceImpl implements SchisandraOssMinioDomainService {

    @Resource
    private SchisandraOssMinioService schisandraOssMinioService;

    @Override
    public Boolean add(SchisandraOssMinioBO schisandraOssMinioBO) {
        SchisandraOssMinio schisandraOssMinio = SchisandraOssMinioBOConverter.INSTANCE.convertBOToEntity(schisandraOssMinioBO);
        schisandraOssMinio.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return schisandraOssMinioService.insert(schisandraOssMinio) > 0;
    }

    @Override
    public Boolean update(SchisandraOssMinioBO schisandraOssMinioBO) {
        SchisandraOssMinio schisandraOssMinio = SchisandraOssMinioBOConverter.INSTANCE.convertBOToEntity(schisandraOssMinioBO);
        return schisandraOssMinioService.update(schisandraOssMinio) > 0;
    }

    @Override
    public Boolean delete(SchisandraOssMinioBO schisandraOssMinioBO) {
        SchisandraOssMinio schisandraOssMinio = new SchisandraOssMinio();
        schisandraOssMinio.setId(schisandraOssMinioBO.getId());
        schisandraOssMinio.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        return schisandraOssMinioService.update(schisandraOssMinio) > 0;
    }

    @Override
    public SchisandraOssMinioBO getMinioConfig(Long userId) {
        SchisandraOssMinio schisandraOssMinio = schisandraOssMinioService.getMinioConfig(userId);
        SchisandraOssMinioBO schisandraOssMinioBO = SchisandraOssMinioBOConverter.INSTANCE.convertEntityToBO(schisandraOssMinio);
        return schisandraOssMinioBO;
    }

    @Override
    public List<SchisandraOssMinioBO> getAllMinioInfo() {
        List<SchisandraOssMinio> allMinioInfo = schisandraOssMinioService.getAllMinioInfo();
        List<SchisandraOssMinioBO> schisandraOssMinioBOS = SchisandraOssMinioBOConverter.INSTANCE.convertEntityToBOList(allMinioInfo);
        return schisandraOssMinioBOS;
    }

}
