package com.oguerreiro.resilient.repository.security;

import java.util.Optional;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.oguerreiro.resilient.repository.ResilientJpaRepository;
import com.oguerreiro.resilient.security.resillient.SecurityGroup;

/**
 * Spring Data JPA repository for the SecurityGroup entity.
 */
@SuppressWarnings("unused")
@Repository
public interface SecurityGroupRepository extends ResilientJpaRepository<SecurityGroup, Long> {
  @Override
  @Query("select securityGroup from SecurityGroup securityGroup left join fetch securityGroup.securityGroupPermissions permissions left join fetch securityGroup.securityGroupPermissions.securityResource resource where securityGroup.id =:id")
  Optional<SecurityGroup> findOneWithEagerRelationships(@Param("id") Long id);

  @Query("select securityGroup from SecurityGroup securityGroup left join fetch securityGroup.securityGroupPermissions permissions left join fetch securityGroup.securityGroupPermissions.securityResource resource where securityGroup.code =:code")
  Optional<SecurityGroup> findOneByCodeWithEagerRelationships(@Param("code") String code);

}
