package com.engine.salary.wrapper;

import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.salaryBill.dto.SalaryBaseSetFormDTO;
import com.engine.salary.entity.salaryBill.dto.SalaryBillAckFeedbackDTO;
import com.engine.salary.entity.salaryBill.dto.salaryBillViewingLimitSetting;
import com.engine.salary.entity.salaryBill.dto.SalaryBillWatermarkDTO;
import com.engine.salary.entity.salaryBill.param.SalaryBaseSetSaveParam;
import com.engine.salary.service.SalaryBillBaseSetService;
import com.engine.salary.service.impl.SalaryBillBaseSetServiceImpl;
import com.google.common.collect.Maps;
import weaver.hrm.User;

import java.util.Map;
import java.util.Objects;

/**
 * @Description: 工资单水印
 * @Author: wangxiangzhong
 * @Date: 2023/5/16 10:17
 */

public class SalaryBillBaseSetWrapper extends Service {

    private SalaryBillBaseSetService getSalaryBillBaseSetService(User user) {
        return ServiceUtil.getService(SalaryBillBaseSetServiceImpl.class, user);
    }


    /**
     * 是否具备工资单水印权限
     *
     * @param currentEmployeeId
     * @param currentTenantKey
     * @return
     */
//    public Boolean isBaseSetHasRight(Long currentEmployeeId, String currentTenantKey) {
//        return taxAgentService.isHasPermission(SalaryBillWatermarkBO.PERMISSION_SET_CODE, currentEmployeeId, currentTenantKey);
//    }

    /**
     * 获取工资单水印设置表单
     *
     * @return
     */
    public SalaryBaseSetFormDTO getBaseSetForm() {
        SalaryBaseSetFormDTO dto = new SalaryBaseSetFormDTO();
        SalaryBillWatermarkDTO salaryBillWatermark = getSalaryBillBaseSetService(user).getWatermarkSetting();
        SalaryBillAckFeedbackDTO salaryBillAckFeedback = getSalaryBillBaseSetService(user).getDefaultAckFeedbackSetting();
        salaryBillViewingLimitSetting salaryBillViewingLimitSetting = getSalaryBillBaseSetService(user).getSalaryBillViewingLimitSetting();
        Integer burningAfterReadingMin = getSalaryBillBaseSetService(user).getBurningAfterReadingMin();
        salaryBillViewingLimitSetting.setBurningAfterReadingMin(burningAfterReadingMin);

        if (Objects.isNull(salaryBillWatermark)) {
            dto.setWatermarkStatus(false);
            Map<String, Object> wmSetting = Maps.newHashMap();
            wmSetting.put("wmClassify", "text");
            dto.setWatermarkSetting(wmSetting);
        } else {
            dto.setWatermarkStatus(salaryBillWatermark.getWatermarkStatus());
            dto.setWatermarkSetting(salaryBillWatermark.getWmSetting());
            dto.setWatermark(salaryBillWatermark.getWatermarkType());
        }
        if (Objects.nonNull(salaryBillAckFeedback)) {
            // 工资单反馈默认设置
            dto.setAckFeedbackSetting(salaryBillAckFeedback);
        }
        dto.setSalaryBillViewingLimitSetting(salaryBillViewingLimitSetting);

        return dto;
    }

    /**
     * 保存工资单模板基础设置
     *
     * @param saveParam
     * @return
     */
    public String saveBaseSet(SalaryBaseSetSaveParam saveParam) {
        return getSalaryBillBaseSetService(user).saveBaseSet(saveParam);
    }

    /**
     * 获取水印预览内容
     * @param salaryBaseSetSaveParam
     */
    public String previewWaterMark(SalaryBaseSetSaveParam salaryBaseSetSaveParam) {
        return getSalaryBillBaseSetService(user).previewWaterMark(salaryBaseSetSaveParam.getWmSetting());
    }
}
