package com.dbnt.faisp.organMgt.service;

import com.dbnt.faisp.organMgt.mapper.OrganConfigMapper;
import com.dbnt.faisp.organMgt.model.OrganConfig;
import com.dbnt.faisp.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> selectOrganListWhereUserOgCd(String ogCd) {
    return organConfigMapper.selectOrganListWhereUserOgCd(ogCd);
  }
}
