package cn.novalon.manage.db.repository;

import cn.novalon.manage.sys.core.domain.SysDictType;
import cn.novalon.manage.sys.core.repository.ISysDictTypeRepository;
import cn.novalon.manage.db.converter.SysDictTypeConverter;
import cn.novalon.manage.db.dao.SysDictTypeDao;
import cn.novalon.manage.db.entity.SysDictTypeEntity;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * 字典类型仓储实现类
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Repository
public class SysDictTypeRepository implements ISysDictTypeRepository {

    private final SysDictTypeDao sysDictTypeDao;
    private final SysDictTypeConverter sysDictTypeConverter;

    public SysDictTypeRepository(SysDictTypeDao sysDictTypeDao, SysDictTypeConverter sysDictTypeConverter) {
        this.sysDictTypeDao = sysDictTypeDao;
        this.sysDictTypeConverter = sysDictTypeConverter;
    }

    @Override
    public Flux<SysDictType> findByDeletedAtIsNull() {
        return sysDictTypeDao.findByDeletedAtIsNull()
                .map(sysDictTypeConverter::toDomain);
    }

    @Override
    public Mono<SysDictType> findById(Long id) {
        return sysDictTypeDao.findById(id)
                .map(sysDictTypeConverter::toDomain);
    }

    @Override
    public Mono<SysDictType> findByDictTypeAndDeletedAtIsNull(String dictType) {
        return sysDictTypeDao.findByDictTypeAndDeletedAtIsNull(dictType)
                .map(sysDictTypeConverter::toDomain);
    }

    @Override
    public Mono<SysDictType> save(SysDictType dictType) {
        SysDictTypeEntity entity = sysDictTypeConverter.toEntity(dictType);
        return sysDictTypeDao.save(entity)
                .map(sysDictTypeConverter::toDomain);
    }

    @Override
    public Mono<Void> deleteByIdAndDeletedAtIsNull(Long id) {
        return sysDictTypeDao.deleteByIdAndDeletedAtIsNull(id);
    }
}