package com.malk.service.vika.impl;

import com.malk.server.vika.VKConf;
import com.malk.server.vika.VKR;
import com.malk.service.vika.VKClient;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
@Slf4j
public class VKImplClient implements VKClient {

    @Autowired
    private VKConf vkConf;

    /**
     * 获取记录
     */
    @Override
    public Map getRecords(String datasheetId, Map extInfo) {
        VKR vkr = (VKR) VKR.doGet("https://vika.cn/fusion/v1/datasheets/" + datasheetId + "/records", vkConf.initTokenHeader(), extInfo, VKR.RC_VK);
        return (Map) vkr.getData();
    }

    /**
     * 获取记录 [最大分页]
     */
    @Override
    public List<Map> getRecordsAll(String datasheetId, Map extInfo) {
        UtilMap.putNotNull(extInfo, "pageSize", 1000);
        return (List<Map>) getRecords(datasheetId, extInfo).get("records");
    }
}
