package com.kamco.cd.kamcoback.postgres.repository.model;

import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;

import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.Optional;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;

public class ModelVerRepositoryImpl extends QuerydslRepositorySupport
    implements ModelVerRepositoryCustom {

  private final JPAQueryFactory queryFactory;
  private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");

  public ModelVerRepositoryImpl(JPAQueryFactory queryFactory) {
    super(ModelMngBakEntity.class);
    this.queryFactory = queryFactory;
  }

  @Override
  public Optional<ModelVerEntity> findModelVerById(Long id) {
    return Optional.ofNullable(
        queryFactory
            .selectFrom(modelVerEntity)
            .where(modelVerEntity.id.eq(id)) // model_ver_uid
            .fetchOne());
  }
}
