package com.izouma.uwip.repo;

import com.izouma.uwip.domain.DomesticPatent;
import com.izouma.uwip.dto.DomesticPatentDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.Optional;

public interface DomesticPatentRepo extends JpaRepository<DomesticPatent, Long>, JpaSpecificationExecutor<DomesticPatent> {
    @Query("update DomesticPatent t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);


    @Query("select new com.izouma.uwip.dto.DomesticPatentDTO(d,p) " +
            "from DomesticPatent d join Patent p on d.patentId = p.id " +
            "where d.id = ?1 and p.del = false and d.del = false")
    Optional<DomesticPatentDTO> findDomesticDTO(Long id);
}