package cn.novalon.gym.manage.db.repository;

import cn.novalon.gym.manage.sys.core.domain.SysDictData;
import cn.novalon.gym.manage.sys.core.repository.ISysDictDataRepository;
import cn.novalon.gym.manage.db.converter.SysDictDataConverter;
import cn.novalon.gym.manage.db.dao.SysDictDataDao;
import cn.novalon.gym.manage.db.entity.SysDictDataEntity;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * 字典数据仓储实现类
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Repository
public class SysDictDataRepository implements ISysDictDataRepository {

    private final SysDictDataDao sysDictDataDao;
    private final SysDictDataConverter sysDictDataConverter;

    public SysDictDataRepository(SysDictDataDao sysDictDataDao, SysDictDataConverter sysDictDataConverter) {
        this.sysDictDataDao = sysDictDataDao;
        this.sysDictDataConverter = sysDictDataConverter;
    }

    @Override
    public Flux<SysDictData> findByDeletedAtIsNull() {
        return sysDictDataDao.findByDeletedAtIsNull()
                .map(sysDictDataConverter::toDomain);
    }

    @Override
    public Flux<SysDictData> findByDictTypeAndDeletedAtIsNull(String dictType) {
        return sysDictDataDao.findByDictTypeAndDeletedAtIsNull(dictType)
                .map(sysDictDataConverter::toDomain);
    }

    @Override
    public Flux<SysDictData> findByDictTypeAndStatusAndDeletedAtIsNull(String dictType, String status) {
        return sysDictDataDao.findByDictTypeAndStatusAndDeletedAtIsNull(dictType, status)
                .map(sysDictDataConverter::toDomain);
    }

    @Override
    public Mono<SysDictData> findById(Long id) {
        return sysDictDataDao.findById(id)
                .map(sysDictDataConverter::toDomain);
    }

    @Override
    public Mono<SysDictData> save(SysDictData dictData) {
        SysDictDataEntity entity = sysDictDataConverter.toEntity(dictData);
        return sysDictDataDao.save(entity)
                .map(sysDictDataConverter::toDomain);
    }

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