package com.zcloud.primeport.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.command.convertor.MkmjGateCoConvertor;
import com.zcloud.primeport.dto.MkmjGatePageQry;
import com.zcloud.primeport.dto.clientobject.MkmjGateCO;
import com.zcloud.primeport.persistence.dataobject.MkmjGateDO;
import com.zcloud.primeport.persistence.repository.MkmjGateRepository;
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:18
 */
@Component
@AllArgsConstructor
public class MkmjGateQueryExe {
    private final MkmjGateRepository mkmjGateRepository;
    private final MkmjGateCoConvertor mkmjGateCoConvertor;

    /**
     * 分页
     *
     * @param mkmjGatePageQry
     * @return
     */
    public PageResponse<MkmjGateCO> execute(MkmjGatePageQry mkmjGatePageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(mkmjGatePageQry);
        PageResponse<MkmjGateDO> pageResponse = mkmjGateRepository.listPage(parmas);
        List<MkmjGateCO> examCenterCOS = mkmjGateCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MkmjGateCO getInfoById(Long id) {
        MkmjGateDO byId = mkmjGateRepository.getById(id);
        return mkmjGateCoConvertor.converDOToCO(byId);
    }

    public Boolean checkName(String gateName, Long passageId, Long id) {
        return mkmjGateRepository.checkName(gateName, passageId, id);
    }
}

