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


import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.convert.SchisandraOssAliBOConverter;
import com.schisandra.oss.domain.service.SchisandraOssAliDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssAli;
import com.schisandra.oss.infra.basic.service.SchisandraOssAliService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 领域service实现了
 *
 * @author landaiqing
 * @since 2024-05-14 20:45:32
 */
@Service
@Slf4j
public class SchisandraOssAliDomainServiceImpl implements SchisandraOssAliDomainService {

    @Resource
    private SchisandraOssAliService schisandraOssAliService;

    @Override
    public Boolean add(SchisandraOssAliBO schisandraOssAliBO) {
        SchisandraOssAli schisandraOssAli = SchisandraOssAliBOConverter.INSTANCE.convertBOToEntity(schisandraOssAliBO);
        schisandraOssAli.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return schisandraOssAliService.insert(schisandraOssAli) > 0;
    }

    @Override
    public Boolean update(SchisandraOssAliBO schisandraOssAliBO) {
        SchisandraOssAli schisandraOssAli = SchisandraOssAliBOConverter.INSTANCE.convertBOToEntity(schisandraOssAliBO);
        return schisandraOssAliService.update(schisandraOssAli) > 0;
    }

    @Override
    public Boolean delete(SchisandraOssAliBO schisandraOssAliBO) {
        SchisandraOssAli schisandraOssAli = new SchisandraOssAli();
        schisandraOssAli.setId(schisandraOssAliBO.getId());
        schisandraOssAli.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        return schisandraOssAliService.update(schisandraOssAli) > 0;
    }

    @Override
    public SchisandraOssAliBO getAliOssConfig(Long userId) {
        SchisandraOssAli schisandraOssAli = schisandraOssAliService.getAliOssConfig(userId);
        SchisandraOssAliBO schisandraOssAliBO = SchisandraOssAliBOConverter.INSTANCE.convertEntityToBO(schisandraOssAli);
        return schisandraOssAliBO;
    }

}
