package com.dbnt.sims.organMgt.service;

import com.dbnt.sims.organMgt.mapper.OrganConfigMapper;
import com.dbnt.sims.organMgt.model.OrganConfig;
import com.dbnt.sims.organMgt.repository.OrganConfigRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OrganConfigService {
  private final OrganConfigRepository organConfigRepository;
  private final OrganConfigMapper organConfigMapper;

  public List<OrganConfig> selectSavedOrganList() {
    return organConfigRepository.findAll();
  }

  public Integer saveOrganConfig(List<OrganConfig> organConfigList) {
    organConfigRepository.deleteByOrganType("OGC003");
    organConfigRepository.deleteByOrganType("OGC002");
    return organConfigRepository.saveAll(organConfigList).size();
  }

  public List<String> selectDownOrganListWhereUserOgCd(String ogCd) {
    return organConfigMapper.selectDownOrganListWhereUserOgCd(ogCd);
  }
  public List<String> selectUpOrganListWhereUserOgCd(String ogCd) {
    List<String> upOrganList = organConfigMapper.selectUpOrganListWhereUserOgCd(ogCd);
    upOrganList.add(ogCd);
    return upOrganList;
  }
}
