package com.icomsys.main_vm.db.jpa.repo.learningTest.dsl;

import com.icomsys.main_vm.biz.rcp.learningTest.vo.SelectIntentTestVO;
import com.icomsys.main_vm.db.jpa.entity.learningTest.QTbIntentTest;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;

import java.util.List;

@Aspect
@Slf4j
@RequiredArgsConstructor
public class TbIntentTestDslRepoImpl implements TbIntentTestDslRepo {

    private final JPAQueryFactory queryFactory;
    private QTbIntentTest qTbIntentTest = QTbIntentTest.tbIntentTest;

    @Override
    public List<SelectIntentTestVO> selectIntentTestList (String oprMngCode) {

        var result = queryFactory.select(
                        Projections.fields(
                                SelectIntentTestVO.class,
                                qTbIntentTest.seq,
                                qTbIntentTest.rowNum,
                                qTbIntentTest.uploadFileName,
                                qTbIntentTest.testCnt,
                                qTbIntentTest.updateId.as("testId"),
                                qTbIntentTest.updateDate.as("testDate"),
                                qTbIntentTest.testResult
                        )
                )
                .from(qTbIntentTest)
                .where(qTbIntentTest.oprMngCode.eq(oprMngCode))
                .orderBy(qTbIntentTest.updateDate.desc())
                .fetch();

        return result;
    }
}
