package com.kamco.cd.kamcoback.members.service;

import com.kamco.cd.kamcoback.common.exception.CustomApiException;
import com.kamco.cd.kamcoback.common.utils.CommonStringUtils;
import com.kamco.cd.kamcoback.members.dto.MembersDto;
import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class AdminService {

  private final MembersCoreService membersCoreService;

  /**
   * 관리자 계정 등록
   *
   * @param addReq
   * @return
   */
  @Transactional
  public Long saveMember(MembersDto.AddReq addReq) {
    if (!CommonStringUtils.isValidPassword(addReq.getPassword())) {
      throw new CustomApiException("WRONG_PASSWORD", HttpStatus.BAD_REQUEST);
    }

    return membersCoreService.saveMembers(addReq);
  }

  /**
   * 관리자 계정 수정
   *
   * @param uuid
   * @param updateReq
   */
  @Transactional
  public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
    membersCoreService.updateMembers(uuid, updateReq);
  }

  /**
   * 사번 중복 체크
   *
   * @param employeeNo
   * @return
   */
  public boolean existsByEmployeeNo(String employeeNo) {
    return membersCoreService.existsByEmployeeNo(employeeNo);
  }
}
