package com.goldenchart.repository;

import com.goldenchart.entity.GcChartWorkspace;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface GcChartWorkspaceRepository extends JpaRepository<GcChartWorkspace, Long> {

    Optional<GcChartWorkspace> findByUserId(Long userId);

    Optional<GcChartWorkspace> findByDeviceId(String deviceId);

    @Query("SELECT w FROM GcChartWorkspace w LEFT JOIN FETCH w.slots WHERE w.userId = :userId")
    Optional<GcChartWorkspace> findWithSlotsByUserId(Long userId);

    @Query("SELECT w FROM GcChartWorkspace w LEFT JOIN FETCH w.slots WHERE w.deviceId = :deviceId")
    Optional<GcChartWorkspace> findWithSlotsByDeviceId(String deviceId);
}
