package com.kamco.cd.kamcoback.postgres.repository.members;

import com.kamco.cd.kamcoback.members.dto.MembersDto;
import com.kamco.cd.kamcoback.postgres.entity.QMemberRoleEntity;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class MembersRoleRepositoryImpl implements MembersRoleRepositoryCutom {

  private final JPAQueryFactory queryFactory;
  private final QMemberRoleEntity memberRoleEntity = QMemberRoleEntity.memberRoleEntity;

  @Override
  public boolean findByUuidAndRoleName(MembersDto.RolesDto rolesDto) {
    return queryFactory
            .select(memberRoleEntity)
            .from(memberRoleEntity)
            .where(
                memberRoleEntity
                    .id
                    .memberUuid
                    .eq(rolesDto.getUuid())
                    .and(memberRoleEntity.id.roleName.eq(rolesDto.getRoleName())))
            .fetchOne()
        != null;
  }
}
