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

import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationScenarioMasterVO;
import com.icomsys.main_vm.biz.rcp.conversation.vo.ConversationScenarioRelatedIntentVO;
import com.icomsys.main_vm.db.jpa.entity.conversation.QTbIntentMaster;
import com.icomsys.main_vm.db.jpa.entity.scenario.QTbScenarioMaster;
import com.icomsys.main_vm.db.jpa.entity.scenario.QTbScenarioRelatedIntent;
import com.icomsys.main_vm.db.jpa.entity.scenario.QTbScenarioRelease;
import com.querydsl.core.QueryResults;
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;

@Aspect
@Slf4j
@RequiredArgsConstructor
public class TbScenarioRelatedIntentRepoDslImpl implements TbScenarioRelatedIntentRepoDsl {
    private final JPAQueryFactory queryFactory;

    private QTbScenarioRelatedIntent qTbScenarioRelatedIntent = QTbScenarioRelatedIntent.tbScenarioRelatedIntent;
    private QTbIntentMaster qTbIntentMaster = QTbIntentMaster.tbIntentMaster;

    @Override
    public QueryResults<ConversationScenarioRelatedIntentVO> findRelatedIntentList(ConversationScenarioMasterVO dto){
        QueryResults<ConversationScenarioRelatedIntentVO> result =
                queryFactory.select(
                        Projections.fields(
                                ConversationScenarioRelatedIntentVO.class,
                                qTbScenarioRelatedIntent.scenarioSeq,
                                qTbScenarioRelatedIntent.intentSeq,
                                qTbIntentMaster.intentName
                        )

                )
                .from(qTbScenarioRelatedIntent)
                .innerJoin(qTbIntentMaster).on(qTbScenarioRelatedIntent.intentSeq.eq(qTbIntentMaster.seq))
                .where(qTbScenarioRelatedIntent.scenarioSeq.eq(dto.getSeq()))
                .fetchResults();

        return result;
    }
}
