package com.dbnt.faisp.main.userInfo.service;

import com.dbnt.faisp.main.userInfo.mapper.UserInfoMapper;
import com.dbnt.faisp.main.userInfo.model.UserInoutLog;
import com.dbnt.faisp.main.userInfo.model.UserRequestLog;
import com.dbnt.faisp.main.userInfo.repository.UserInoutLogRepository;
import com.dbnt.faisp.main.userInfo.repository.UserRequestLogRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
@RequiredArgsConstructor
public class UserLogService {
  private final UserRequestLogRepository requestLogRepository;
  private final UserInoutLogRepository inoutLogRepository;
  private final UserInfoMapper userInfoMapper;

  @Transactional
  public void saveRequestLog(UserRequestLog requestLog){
    LocalDateTime dateTime = LocalDateTime.now();
    requestLog.setUlKey(dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
    requestLog.setWrtDt(dateTime);
    requestLogRepository.save(requestLog);
  }
  @Transactional
  public void saveInoutLog(UserInoutLog inoutLog){
    LocalDateTime dateTime = LocalDateTime.now();
    inoutLog.setInoutKey(dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
    inoutLog.setWrtDt(dateTime);
    inoutLogRepository.save(inoutLog);
  }

  public List<UserRequestLog> selectRequestLogList(UserRequestLog requestLog) {
    return userInfoMapper.selectRequestLogList(requestLog);
  }

  public Integer selectRequestLogListCnt(UserRequestLog requestLog) {
    return userInfoMapper.selectRequestLogListCnt(requestLog);
  }

  public List<UserInoutLog> selectInoutLogList(UserInoutLog inoutLog) {
    return userInfoMapper.selectInoutLogList(inoutLog);
  }

  public Integer selectInoutLogListCnt(UserInoutLog inoutLog) {
    return userInfoMapper.selectInoutLogListCnt(inoutLog);
  }
}
