package com.zcloud.primeport.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.command.convertor.VideoCoConvertor;
import com.zcloud.primeport.dto.VideoPageQry;
import com.zcloud.primeport.dto.clientobject.VideoCO;
import com.zcloud.primeport.persistence.dataobject.VideoDO;
import com.zcloud.primeport.persistence.repository.VideoRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:31
 */
@Component
@AllArgsConstructor
public class VideoQueryExe {
    private final VideoRepository videoRepository;
    private final VideoCoConvertor videoCoConvertor;

    /**
     * 分页
     *
     * @param videoPageQry
     * @return
     */
    public PageResponse<VideoCO> execute(VideoPageQry videoPageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(videoPageQry);
        PageResponse<VideoDO> pageResponse = videoRepository.listPageWithOnline(parmas);
        List<VideoCO> examCenterCOS = videoCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public VideoCO getInfoById(Long id) {
        VideoDO byId = videoRepository.getById(id);
        return videoCoConvertor.converDOToCO(byId);
    }
}

