package com.kospo.talk.service.impl;

import com.kospo.talk.config.exception.ErrorCode;
import com.kospo.talk.exception.CustomException;
import com.kospo.talk.model.SmUser;
import com.kospo.talk.model.SmUserId;
import com.kospo.talk.model.Work;
import com.kospo.talk.payload.ISmUserDto;
import com.kospo.talk.payload.SmUserDto;
import com.kospo.talk.repository.SmUserRepository;
import com.kospo.talk.repository.WorkRepository;
import com.kospo.talk.service.SmUserService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class SmUserServiceImpl implements SmUserService {
    private final SmUserRepository smUserRepository;
    private final WorkRepository workRepository;


    @Transactional
    @Override
    public List<SmUserDto> findByWorkId(String workId) {
        return smUserRepository.findByIdWorkId(workId).stream().map(SmUserDto::to).toList();
    }

    @Override
    public long countByOnlineYnAndWorkIdExceptSabun(String workId, String sabun) {
        return smUserRepository.countByIdWorkIdExceptSabun(workId, sabun);
    }

    @Override
    public long countByOnlineYnAndWorkId(String workId) {
        return smUserRepository.countByIdWorkId(workId);
    }

    @Override
    public List<SmUser> findBySabun(String sabun) {
        return smUserRepository.findByIdSabun(sabun);
    }

    @Override
    public List<ISmUserDto> findBySmUserInSabun(String sabun) {
        return smUserRepository.findBySmUserInSabun(sabun);
    }

    @Override
    public List<ISmUserDto> findWorkOnlineInSabun(String sabun) {
        return smUserRepository.findWorkOnlineInSabun(sabun);
    }
}
