package com.malk.service.dingtalk.impl;

import com.malk.server.dingtalk.DDR;
import com.malk.server.dingtalk.DDR_RECORDS;
import com.malk.service.dingtalk.DDClient_Notable;
import com.malk.utils.UtilMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Service
@Slf4j
public class DDImplClient_Notable implements DDClient_Notable {


    @Override
    public List<Map> getRecords(String access_token,String baseId, String sheetIdOrName, String operatorId, Map<String, Object> params) {
        Map param = UtilMap.map("x-acs-dingtalk-access-token", access_token);
        return (List<Map>) DDR_RECORDS.doPost("https://api.dingtalk.com/v1.0/notable/bases/"+baseId+"/sheets/"+sheetIdOrName+"/records/list?operatorId="+operatorId, param, null, params).getRecords();
    }

    @Override
    public void updateRecords(String access_token,String baseId, String sheetIdOrName, String operatorId, List<Map> records) {
        Map param = UtilMap.map("x-acs-dingtalk-access-token", access_token);
        Map params = UtilMap.map("records", records);
        DDR_RECORDS.doPut("https://api.dingtalk.com/v1.0/notable/bases/"+baseId+"/sheets/"+sheetIdOrName+"/records?operatorId="+operatorId, param, null, params);
    }
}
