package com.izouma.jmrh.service;

import com.izouma.jmrh.domain.*;
import com.izouma.jmrh.dto.SndDTO;
import com.izouma.jmrh.enums.ResSnDType;
import com.izouma.jmrh.exception.BusinessException;
import com.izouma.jmrh.repo.CollectRepo;
import com.izouma.jmrh.repo.ResourceSupplyAndDemandRepo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class CollectService {

    private CollectRepo                 collectRepo;
    private ResourceSupplyAndDemandRepo resourceSupplyAndDemandRepo;

    public void collectSnd(Long userId, Long sndId) {
        Collect collect = collectRepo.findByUserIdAndSndId(userId, sndId);
        if (collect != null) {
            collectRepo.delete(collect);
        } else {
            collectRepo.save(Collect.builder()
                    .userId(userId)
                    .sndId(sndId)
                    .build());
        }
    }
}
