package com.zcloud.basic.info.command.query;

import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.basic.info.command.convertor.ProblemFeedbackCoConvertor;
import com.zcloud.basic.info.dto.ProblemFeedbackPageQry;
import com.zcloud.basic.info.dto.ProblemFeedbackListQry;
import com.zcloud.basic.info.dto.clientobject.ProblemFeedbackCO;
import com.zcloud.basic.info.persistence.dataobject.ProblemFeedbackDO;
import com.zcloud.basic.info.persistence.repository.ProblemFeedbackRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Map;


/**
 * web-app
 *
 * @Author SondonYong
 * @Date 2025-12-06 11:26:34
 */
@Component
@AllArgsConstructor
public class ProblemFeedbackQueryExe {
    private final ProblemFeedbackRepository problemFeedbackRepository;
    private final ProblemFeedbackCoConvertor problemFeedbackCoConvertor;

    /**
     * 分页
     *
     * @return
     */
    public PageResponse<ProblemFeedbackCO> execute(ProblemFeedbackPageQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        PageResponse<ProblemFeedbackDO> pageResponse = problemFeedbackRepository.listPage(params);
        List<ProblemFeedbackCO> examCenterCOS = problemFeedbackCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MultiResponse<ProblemFeedbackCO> execute(ProblemFeedbackListQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        List<ProblemFeedbackDO> list = problemFeedbackRepository.list(params);
        List<ProblemFeedbackCO> examCenterCOS = problemFeedbackCoConvertor.converDOsToCOs(list);
        return MultiResponse.of(examCenterCOS);
    }

    public SingleResponse<ProblemFeedbackCO> execute(Long id) {
        SingleResponse<ProblemFeedbackDO> problemFeedbackDO = problemFeedbackRepository.getInfoById(id);
        ProblemFeedbackCO co = new ProblemFeedbackCO();
        BeanUtils.copyProperties(problemFeedbackDO.getData(), co);
        return SingleResponse.of(co);
    }

}

