package com.dbnt.faisp.authMgt.service;

import com.dbnt.faisp.authMgt.mapper.AuthMgtMapper;
import com.dbnt.faisp.authMgt.model.AccessConfig;
import com.dbnt.faisp.authMgt.model.ApprovalConfig;
import com.dbnt.faisp.authMgt.model.AuthMgt;
import com.dbnt.faisp.authMgt.repository.AccessConfigRepository;
import com.dbnt.faisp.authMgt.repository.ApprovalConfigRepository;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@RequiredArgsConstructor
public class AuthMgtService {
  private final AuthMgtMapper authMgtMapper;
  private final AccessConfigRepository accessConfigRepository;
  private final ApprovalConfigRepository approvalConfigRepository;

  public List<AccessConfig> selectAccessConfigList(Integer userSeq, String url) {
    Map<String, Object> params = new HashMap<>();
    params.put("userSeq", userSeq);
    params.put("menuUrl", url);
    return authMgtMapper.selectAccessConfigList(params);
  }

  public List<ApprovalConfig> selectApprovalConfigList(Integer userSeq, String url) {
    Map<String, Object> params = new HashMap<>();
    params.put("userSeq", userSeq);
    params.put("menuUrl", url);
    return authMgtMapper.selectApprovalConfigList(params);
  }

  public void saveAuth(AuthMgt authMgt) {
    accessConfigRepository.saveAll(authMgt.getAccessConfigList());
    approvalConfigRepository.saveAll(authMgt.getApprovalConfigList());
  }
}
