package cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.repository;

import cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.TcaElctrnNticSndngResult;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

import static cokr.xit.ens.biz.traffic.cheonan.signtalk.domain.QTcaElctrnNticSndngResult.tcaElctrnNticSndngResult;

@RequiredArgsConstructor
public class TcaElctrnNticSndngResultRepositoryImpl implements TcaElctrnNticSndngResultRepositoryCustom {

    private final JPAQueryFactory query;

    @Override
    public void modifyByElctrnNticSndngResults(List<TcaElctrnNticSndngResult> tcaElctrnNticSndngResults) {
        tcaElctrnNticSndngResults.forEach(data ->
                        query.update(tcaElctrnNticSndngResult)
                                .set(tcaElctrnNticSndngResult.sndngSe, data.getSndngSe())
                                .set(tcaElctrnNticSndngResult.sndngResultSttus, data.getSndngResultSttus())
                                .set(tcaElctrnNticSndngResult.requstDt, data.getRequstDt())
                                .set(tcaElctrnNticSndngResult.inqireDt, data.getInqireDt())
                                .set(tcaElctrnNticSndngResult.readngDt, data.getReadngDt())
                                .set(tcaElctrnNticSndngResult.errorCn, data.getErrorCn())
//						.set(tcaElctrnNticSndngResult.create, FieldCreate.builder().build())
                                .set(tcaElctrnNticSndngResult.lastUpdtDt, LocalDateTime.now())
                                .where(tcaElctrnNticSndngResult.elctrnNticSndngDetailId.eq(data.getElctrnNticSndngDetailId()))
                                .execute()
        );
    }


}
