package com.gcsc.connection.apikey.repository;

import com.gcsc.connection.apikey.entity.SnpApiPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface SnpApiPermissionRepository extends JpaRepository<SnpApiPermission, Long> {

    Optional<SnpApiPermission> findByApiKeyApiKeyIdAndApiApiIdAndIsActiveTrue(Long apiKeyId, Long apiId);

    List<SnpApiPermission> findByApiKeyApiKeyId(Long apiKeyId);

    @Modifying
    @Query("DELETE FROM SnpApiPermission p WHERE p.apiKey.apiKeyId = :apiKeyId")
    void deleteByApiKeyApiKeyId(Long apiKeyId);
}
