package cokr.xit.ens.modules.kkoalimtalk.domain.repository;

import cokr.xit.ens.modules.kkoalimtalk.domain.SendDetailKkoAlimtalk;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

import java.util.List;

import static cokr.xit.ens.modules.common.ctgy.intgrnbill.support.entity.QBill.bill;
import static cokr.xit.ens.modules.common.domain.QSendMast.sendMast;
import static cokr.xit.ens.modules.kkoalimtalk.domain.QSendDetailKkoAlimtalk.sendDetailKkoAlimtalk;

@RequiredArgsConstructor
public class SendDetailKkoAlimtalkRepositoryImpl implements SendDetailKkoAlimtalkRepositoryCustom {

    private final JPAQueryFactory query;


    @Override
    public List<SendDetailKkoAlimtalk> findAllFetchBySendMastId(Long sendMastId) {
        return query.selectFrom(sendDetailKkoAlimtalk)
                .innerJoin(sendDetailKkoAlimtalk.sendMast, sendMast).fetchJoin()
//                .leftJoin(sendDetailKkoAlimtalk.kkoBillMast, kkoBillMast)
                .leftJoin(sendDetailKkoAlimtalk.bill, bill).fetchJoin()
                .where(sendDetailKkoAlimtalk.sendMast.sendMastId.eq(sendMastId))
                .fetch()
                ;
    }
//
//    @Override
//    public List<SendDetailKkoAlimtalk> findAllFetchBySendMastIdAndMkBillUseYAndUrlIsNull(Long sendMastId, boolean urlIsNull) {
//        return query.selectFrom(sendDetailKkoAlimtalk)
//                .innerJoin(sendDetailKkoAlimtalk.sendMast, sendMast)
//                .fetchJoin()
//                .leftJoin(sendDetailKkoAlimtalk.kkoBillMast, kkoBillMast)
//                .fetchJoin()
//                .where(sendDetailKkoAlimtalk.sendMast.sendMastId.eq(sendMastId)
//                        .and(sendDetailKkoAlimtalk.mkBillUseYn.eq("Y"))
//                        .and(urlIsNull ? sendDetailKkoAlimtalk.kkoBillMast.url.isNull() : sendDetailKkoAlimtalk.kkoBillMast.url.isNotNull())
//                )
//                .fetch()
//                ;
//    }
//
//    @Override
//    public List<SendMast> findAllSendMastByMsgIdxInPostSeAndStatCdIn(List<String> msgIdxs, PostSeCd postSeCd, List<StatCd> statCds) {
//        return query.select(sendMast)
//                .from(sendDetailKkoAlimtalk)
//                .innerJoin(sendDetailKkoAlimtalk.sendMast, sendMast)
//                .where(sendDetailKkoAlimtalk.msgIdx.in(msgIdxs)
//                        .and(sendMast.postSe.eq(postSeCd))
//                        .and(sendMast.statCd.in(statCds))
//                )
//                .groupBy(sendMast)
//                .fetch()
//                ;
//    }


}
