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

import cn.novalon.gym.manage.notify.core.domain.SysNotice;
import cn.novalon.gym.manage.notify.core.repository.ISysNoticeRepository;
import cn.novalon.gym.manage.db.converter.SysNoticeConverter;
import cn.novalon.gym.manage.db.dao.SysNoticeDao;
import cn.novalon.gym.manage.db.entity.SysNoticeEntity;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * 通知公告仓储实现类
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Repository
public class SysNoticeRepository implements ISysNoticeRepository {

    private final SysNoticeDao sysNoticeDao;
    private final SysNoticeConverter sysNoticeConverter;

    public SysNoticeRepository(SysNoticeDao sysNoticeDao, SysNoticeConverter sysNoticeConverter) {
        this.sysNoticeDao = sysNoticeDao;
        this.sysNoticeConverter = sysNoticeConverter;
    }

    @Override
    public Flux<SysNotice> findByDeletedAtIsNull() {
        return sysNoticeDao.findByDeletedAtIsNull()
                .map(sysNoticeConverter::toDomain);
    }

    @Override
    public Flux<SysNotice> findByStatusAndDeletedAtIsNull(String status) {
        return sysNoticeDao.findByStatusAndDeletedAtIsNull(status)
                .map(sysNoticeConverter::toDomain);
    }

    @Override
    public Mono<SysNotice> findById(Long id) {
        return sysNoticeDao.findById(id)
                .map(sysNoticeConverter::toDomain);
    }

    @Override
    public Mono<SysNotice> save(SysNotice notice) {
        SysNoticeEntity entity = sysNoticeConverter.toEntity(notice);
        return sysNoticeDao.save(entity)
                .map(sysNoticeConverter::toDomain);
    }

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