package com.zcloud.domain.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.domain.command.convertor.DomainGroupUserCoConvertor;
import com.zcloud.domain.dto.DomainGroupUserPageQry;
import com.zcloud.domain.dto.clientobject.DomainGroupUserCO;
import com.zcloud.domain.persistence.dataobject.DomainGroupUserDO;
import com.zcloud.domain.persistence.repository.DomainGroupUserRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:29:43
 */
@Component
@AllArgsConstructor
public class DomainGroupUserQueryExe {
    private final DomainGroupUserRepository domainGroupUserRepository;
    private final DomainGroupUserCoConvertor domainGroupUserCoConvertor;

    /**
     * 分页
     *
     * @param domainGroupUserPageQry
     * @return
     */
    public PageResponse<DomainGroupUserCO> execute(DomainGroupUserPageQry domainGroupUserPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(domainGroupUserPageQry);
        PageResponse<DomainGroupUserDO> pageResponse = domainGroupUserRepository.listPage(params);
        List<DomainGroupUserCO> examCenterCOS = domainGroupUserCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public List<DomainGroupUserCO> listAll(DomainGroupUserPageQry qry) {
        List<DomainGroupUserDO> listByGroupId = domainGroupUserRepository.getListByGroupId(qry.getDomainGroupId());
        return domainGroupUserCoConvertor.converDOsToCOs(listByGroupId);
    }
}

