/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 */
package org.springblade.transport.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.UserCache;
import org.springblade.transport.pojo.entity.LoadingManage;
import org.springblade.transport.pojo.vo.LoadingManageVO;

import java.util.Objects;

/**
 * 配载管理包装类
 *
 * @author Chill
 */
public class LoadingManageWrapper extends BaseEntityWrapper<LoadingManage, LoadingManageVO> {

	public static LoadingManageWrapper build() {
		return new LoadingManageWrapper();
	}

	@Override
	public LoadingManageVO entityVO(LoadingManage loadingManage) {
		LoadingManageVO loadingManageVO = Objects.requireNonNull(BeanUtil.copyProperties(loadingManage, LoadingManageVO.class));
		loadingManageVO.setCreateUserName(UserCache.getUserRealName(loadingManage.getCreateUser()));
		loadingManageVO.setUpdateUserName(UserCache.getUserRealName(loadingManage.getUpdateUser()));
		Long currentDeptId = Func.firstLong(AuthUtil.getDeptId());
		loadingManageVO.setReadonly(currentDeptId != null && !Objects.equals(loadingManage.getDeptId(), currentDeptId));
		loadingManageVO.setBusinessStatusName(businessStatusName(loadingManage.getBusinessStatus()));
		return loadingManageVO;
	}

	private String businessStatusName(String status) {
		if (status == null) {
			return "未知";
		}
		return switch (status) {
			case "draft" -> "草稿";
			case "pending" -> "待执行";
			case "running" -> "进行中";
			case "completed" -> "已完成";
			case "cancelled" -> "已取消";
			default -> "未知";
		};
	}

}
