package com.engine.salary.wrapper;

import cn.hutool.core.collection.CollUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.push.dto.PushRecordDTO;
import com.engine.salary.entity.push.dto.PushRecordDetailDTO;
import com.engine.salary.entity.push.dto.PushSettingDTO;
import com.engine.salary.entity.push.dto.PushSettingItemDTO;
import com.engine.salary.entity.push.param.*;
import com.engine.salary.entity.push.po.PushSettingItemPO;
import com.engine.salary.entity.push.po.PushSettingPO;
import com.engine.salary.remote.mode.cmd.GetModeList;
import com.engine.salary.service.PushService;
import com.engine.salary.service.impl.PushServiceImpl;
import com.engine.salary.util.page.PageInfo;
import weaver.hrm.User;

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


public class PushWrapper extends Service {

    private PushService getPushService(User user) {
        return ServiceUtil.getService(PushServiceImpl.class, user);
    }


    public Object modeList() {
        Map<String, Object> map = new HashMap<>();
        map.put("appid", 1);
        map.put("appidForAppname", 2);
        map.put("aLLorCurrentKey", 1);
        Map<String, Object> execute = commandExecutor.execute(new GetModeList(map, user));

        return execute;
    }

    public PageInfo<PushSettingDTO> settingList(PushSettingQueryParam param) {
        return getPushService(user).settingList(param);
    }

    public PushSettingPO save(PushSettingSaveParam param) {
        return getPushService(user).save(param);
    }


    public void delete(Long id) {
        getPushService(user).delete(id);
    }

    public PageInfo<PushSettingItemDTO> itemList(PushSettingItemQueryParam param) {
        return getPushService(user).itemList(param);
    }

    public PushSettingItemPO saveItem(PushSettingItemSaveParam param) {
        return getPushService(user).saveItem(param);
    }

    public void deleteItem(Long id) {
        getPushService(user).deleteItem(id);
    }

    public void createPushRecord(CreatePushParam param) {
        param.getSalaryAcctRecordIds().forEach(id -> {
            getPushService(user).createPushRecord(id);
        });
    }

    public void push(PushParam param) {
        List<Long> ids = param.getIds();
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        ids.forEach(id -> {
            getPushService(user).push(id);
        });
    }

    public void withdraw(WithdrawParam param) {
        List<Long> ids = param.getIds();
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        ids.forEach(id -> {
            getPushService(user).withdraw(id);
        });
    }


    public PageInfo<PushRecordDTO> recordList(RecordListQueryParam param) {
        return getPushService(user).recordList(param);
    }

    public PageInfo<PushRecordDetailDTO> recordDetailList(RecordDetailListQueryParam param) {
        return getPushService(user).recordDetailList(param);
    }
}
