package com.psg.dlsysinfo.dl_sysinfo_server.repository;

import com.psg.dlsysinfo.dl_sysinfo_server.entity.Devices;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface DevicesRepository extends JpaRepository<Devices, Long> {

    Optional<Devices> findByHashedHostname(String hashedHostname);

    List<Devices> findByClient_ClientId(Long clientId); // ← by Long ID (DB FK)
    List<Devices> findByClient_ClientIdentifier(String clientIdentifier); // ← ✅ by idauth token
    @Query("SELECT d.deviceId FROM Devices d WHERE d.client.clientId = :clientId")
    List<Long> findDeviceIdsByClientId(@Param("clientId") Long clientId);
}

