package nckd.jimin.jyyy.fi.plugin.form;

import com.alibaba.druid.util.StringUtils;
import kd.bos.entity.operate.result.IOperateInfo;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.list.plugin.AbstractListPlugin;
import java.util.List;

/**
 * 费用申请单
 * @author wanghaiwu_kd
 * @date 2026/01/14
 */
public class DailyApplyBillSetHideListPlugin extends AbstractListPlugin {
    @Override
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        super.afterDoOperation(afterDoOperationEventArgs);

        String operationKey = afterDoOperationEventArgs.getOperateKey();

        if("nckd_hidebill".equals(operationKey) || "nckd_unhidebill".equals(operationKey)){
            OperationResult operationResult = afterDoOperationEventArgs.getOperationResult();
            operationResult.setShowMessage(false);

            String message = operationResult.getMessage();

            if(!StringUtils.isEmpty(message) && (message.contains("设置隐藏成功") || message.contains("取消隐藏成功"))){
                this.getView().showSuccessNotification(message);
                this.getView().invokeOperation("refresh");
            } else {
                List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo();
                boolean isSuccess = operationResult.isSuccess();
                if (errorInfos.size() > 0) {
                    operationResult.setSuccess(false);
                    StringBuffer msg = new StringBuffer();
                    for (IOperateInfo errInfo : errorInfos) {
                        msg.append(errInfo.getMessage()).append("\r\n");
                    }
                    message = message + "\r\n" + msg.toString();
                }

                if (!StringUtils.isEmpty(message)) {
                    this.getView().showErrorNotification(message);
                }
            }
        }
    }
}
