/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.nh.wrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.nh.pojo.dto.open.YXPowerStationDTO;
import org.springblade.modules.nh.pojo.entity.PowerStationEntity;
import org.springblade.modules.nh.pojo.vo.PowerStationVO;
import org.springblade.modules.nh.pojo.vo.StationStaticsVO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 电站 包装类,返回视图层所需的字段
 *
 * @author AlexWang
 * @since 2024-05-31
 */
public class PowerStationWrapper extends BaseEntityWrapper<PowerStationEntity, PowerStationVO>  {

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

	@Override
	public PowerStationVO entityVO(PowerStationEntity powerStation) {
		PowerStationVO powerStationVO = Objects.requireNonNull(BeanUtil.copyProperties(powerStation, PowerStationVO.class));

		//User createUser = UserCache.getUser(powerStation.getCreateUser());
		//User updateUser = UserCache.getUser(powerStation.getUpdateUser());
		//powerStationVO.setCreateUserName(createUser.getName());
		//powerStationVO.setUpdateUserName(updateUser.getName());

		return powerStationVO;
	}

	public IPage<StationStaticsVO> pageStaticsVO(IPage<PowerStationEntity> pages) {
		List<StationStaticsVO> records = this.staticsListVO(pages.getRecords());
		IPage<StationStaticsVO> pageVo = new Page(pages.getCurrent(), pages.getSize(), pages.getTotal());
		pageVo.setRecords(records);
		return pageVo;
	}

	public List<StationStaticsVO> staticsListVO(List<PowerStationEntity> list) {
		return (List)list.stream().map(this::staticsVO).collect(Collectors.toList());
	}

	public StationStaticsVO staticsVO(PowerStationEntity powerStation) {

		StationStaticsVO stationStaticsVO = Objects.requireNonNull(BeanUtil.copyProperties(powerStation, StationStaticsVO.class));

		//User createUser = UserCache.getUser(powerStation.getCreateUser());
		//User updateUser = UserCache.getUser(powerStation.getUpdateUser());
		//powerStationVO.setCreateUserName(createUser.getName());
		//powerStationVO.setUpdateUserName(updateUser.getName());

		return stationStaticsVO;
	}

	public YXPowerStationDTO entityYXDTO(PowerStationEntity powerStation) {
		YXPowerStationDTO dto = Objects.requireNonNull(BeanUtil.copyProperties(powerStation, YXPowerStationDTO.class));

		//User createUser = UserCache.getUser(powerStation.getCreateUser());
		//User updateUser = UserCache.getUser(powerStation.getUpdateUser());
		//powerStationVO.setCreateUserName(createUser.getName());
		//powerStationVO.setUpdateUserName(updateUser.getName());

		return dto;
	}

}
