package com.bocloud.ims.service.resource;

import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.Param;
import com.bocloud.common.utils.GridHelper;
import com.bocloud.ims.entity.resource.ResourceProtocol;
import com.bocloud.ims.interfaces.resource.ResourceProtocolService;
import com.bocloud.ims.repository.resource.ResourceProtocolRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service("resourceProtocolService")
public class ResourceProtocolServiceImpl implements ResourceProtocolService {

    @Autowired
    private ResourceProtocolRepository resourceProtocolRepository;

    @Override
    public BocloudResult<GridBean<ResourceProtocol>> list(Pager pager) {

        int page = pager.getPage();
        int rows = pager.getRows();
        List<Param> params = pager.getParams();
        Map<String, String> sorter = pager.getSorter();
        boolean simple = pager.getSimple();

        List<ResourceProtocol> list = resourceProtocolRepository.list(page, rows, params, sorter);
        int total = resourceProtocolRepository.count(params);
        GridBean gridBean = GridHelper.getBean(page, rows, total, list);
        return new BocloudResult<>(true, gridBean, "Success");
    }
}
