package com.bocloud.ims.interfaces.resource;

import com.alibaba.fastjson.JSONArray;
import com.bocloud.cmp.entity.enums.CloudProvider;
import com.bocloud.cmp.model.HostOperateModel;
import com.bocloud.cmp.model.RackDevice;
import com.bocloud.cmp.model.SwitchModel;
import com.bocloud.common.model.*;
import com.bocloud.ims.entity.resource.AlarmThreshold;
import com.bocloud.ims.entity.resource.CloudServer;
import com.bocloud.ims.entity.resource.Server;
import com.bocloud.ims.entity.resource.ServerConfig;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface ServerService {
	default CloudProvider getCloudVendorType(Server server) {
		return null;
	}

	/**
	 * 查询主机列表
	 *
	 * @param pager
	 * @return
	 */
	BocloudResult<GridBean> list(Pager pager);

	/**
	 * 物理主机用 添加主机
	 *
	 * @param params
	 * @param context
	 * @param isImport
	 * @param instance
	 * @return
	 */
	default BocloudResult create(String params, RequestContext context, Boolean isImport, String instance) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 更新
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	BocloudResult<String> modify(String params, RequestContext context);

	/**
	 * 根据uuid修改物理主机
	 *
	 * @param params
	 * @param uuid
	 * @param context
	 * @return 操作结果
	 * @author sxp
	 * @since Mar 7, 2018
	 */
	BocloudResult modifyByUuid(String params, String uuid, RequestContext context);

	/**
	 * 逻辑删除主机
	 *
	 * @param id
	 * @param force
	 * @param context
	 * @return
	 */
	BocloudResult remove(Long id, Boolean force, RequestContext context);

	/**
	 * 查询主机详细
	 *
	 * @param id the id
	 * @return the result
	 */
	BocloudResult<Server> basic(Long id);

	/**
	 * 得到当前主机的基本信息和统计信息
	 *
	 * @param id the id
	 * @return the result
	 */
	BocloudResult detail(Long id);

	/**
	 * @param rackDevice
	 * @param context
	 * @return
	 */
	default BocloudResult inRack(RackDevice rackDevice, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 移出机柜
	 *
	 * @param id      the server id
	 * @param context the context id
	 * @return the result
	 */
	default BocloudResult outRack(Long id, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 查询空闲主机列表
	 *
	 * @return the result
	 */
	default BocloudResult freePMs() {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 启动主机
	 *
	 * @param id
	 * @param context
	 * @return the result
	 */
	BocloudResult start(Long id, RequestContext context);

	/**
	 * 关闭主机
	 *
	 * @param id
	 * @param context
	 * @return the result
	 */
	BocloudResult stop(Long id, RequestContext context);

	/**
	 * 重启主机
	 *
	 * @param id
	 * @param context
	 * @return the result
	 */
	BocloudResult restart(Long id, RequestContext context);

	/**
	 * 隔离主机
	 *
	 * @param id
	 * @param id
	 * @return the result
	 */
	BocloudResult<String> isolate(Long id, RequestContext context);

	/**
	 * 恢复主机
	 *
	 * @param id the id
	 * @param id the context id
	 * @return the result
	 */
	BocloudResult<String> recover(Long id, RequestContext context);

	/**
	 * 查看IP是否存在
	 *
	 * @param ip the manage ip
	 * @return the result
	 */
	BocloudResult exists(String ip);

	/**
	 * 通过IP查询当前主机信息
	 *
	 * @author sxp
	 * @since V1.0 Nov 4, 2016
	 */
	Server detail(String ip);

	/**
	 * 物理主机用 物理机批量启动
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	default BocloudResult batchStart(String params, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 物理主机用 物理机批量停止
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	default BocloudResult batchStop(String params, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 物理主机用 物理机批量删除
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	default BocloudResult batchRemove(String params, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * vmware用
	 * <p>
	 * 创建标准交换机
	 *
	 * @param switchModel
	 * @param context
	 * @return
	 */
	default BocloudResult createVSwitch(SwitchModel switchModel, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 通过hostname 和venderid 查询云主机
	 *
	 * @param venderId
	 * @param hostName
	 * @return
	 **/
	BocloudResult<List<CloudServer>> listvmByvhost(long venderId, String hostName);

	/**
	 * vmware用
	 * <p>
	 * 断开连接
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	default BocloudResult disconn(Long id, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * vmware用 连接
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	default BocloudResult reconn(Long id, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * vmware用 进入维护模式
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	default BocloudResult entermaintain(Long id, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * vmware用 退出维护模式
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	default BocloudResult exitmaintain(Long id, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * vmware用 移动
	 *
	 * @param model
	 * @param context
	 * @return
	 */
	default BocloudResult move(HostOperateModel model, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 云平台用 添加
	 *
	 * @param model   信息
	 * @param context
	 * @return 操作结果
	 */
	default BocloudResult create(HostOperateModel model, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * 更新服务器与ResourceGroup的绑定
	 *
	 * @param ids
	 * @param resourceGroup
	 * @param id
	 * @return
	 */
	BocloudResult<String> updateResourceGroup(String[] ids, String resourceGroup, Long id);

	/**
	 * 查询指定集群下的宿主机
	 *
	 * @param clusterId
	 * @return
	 */
	BocloudResult<List<Server>> listByCluster(Long clusterId);

	/**
	 * 查询默认集群下的宿主机(POWERVC)
	 *
	 * @return
	 */
	BocloudResult<List<Server>> listByDefaultCluster(long vendorId);

	/**
	 * 查询指定云平台下的宿主机
	 *
	 * @param vendorId
	 * @return
	 */
	BocloudResult<List<Server>> listByVendor(Long vendorId);

	/**
	 * 更新物理主机状态
	 *
	 * @param params 参数
	 * @param uuid   物理主机的uuid
	 * @return 操作结果
	 * @author sxp
	 * @since Mar 12, 2018
	 */
	default BocloudResult updateStatus(String params, String uuid) {
		return new BocloudResult(false, ServerService.class.getSimpleName() + "的updateStatus方法未实现");
	}

	/**
	 * 设置告警阈值
	 *
	 * @param alarmThreshold
	 * @return
	 */
	BocloudResult<String> createAlarm(AlarmThreshold alarmThreshold);

	/**
	 * 获取告警阈值
	 *
	 * @param target
	 * @return
	 */
	BocloudResult<AlarmThreshold> getAlarm(Long target);

	/**
	 * vmware用 查询性能数据
	 *
	 * @param params
	 * @return
	 */
	default BocloudResult performance(String params, Long id, RequestContext context) {
		return new BocloudResult(false, ServerService.class.getSimpleName() + "的performance方法未实现");
	}

	/**
	 * 物理主机用 下载模板
	 *
	 * @param paramsMap
	 * @return
	 */
	default BocloudResult<Map<String, Object>> download(Map<String, Object> paramsMap) {
		return new BocloudResult(false, ServerService.class.getSimpleName() + "的download方法未实现");
	}

	/**
	 * 物理主机用 上传excel文件批量新增
	 *
	 * @param paramsMap
	 * @param excel
	 * @param contextId
	 * @param instance
	 * @return
	 * @throws IOException
	 */
	default BocloudResult upload(Map<String, Object> paramsMap, MultipartFile excel, Long contextId, String instance)
			throws IOException {
		return new BocloudResult(false, ServerService.class.getSimpleName() + "的upload方法未实现");
	}

	public BocloudResult licenseCheck(Long vendorId, Integer pm, Integer vm);

	/**
	 * 根据ip查询宿主机id
	 *
	 * @param ip
	 * @return
	 */
	BocloudResult<Server> queryByIp(String ip);

	/**
	 * 物理主机用 修改机房机柜
	 *
	 * @param id
	 * @param rackId
	 * @param context
	 * @return
	 */
	default BocloudResult patch(Long id, Long rackId, RequestContext context) {
		return new BocloudResult(false, ServerService.class.getSimpleName() + "的patch方法未实现");
	}

	/**
	 * 批量修改标签
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	BocloudResult<String> batchModifyLabel(String params, RequestContext context);

	/**
	 * 查询已挂载给访问路径的网关服务器
	 *
	 * @param page
	 * @param rows
	 * @param id
	 * @param params
	 * @return
	 */
	public BocloudResult listServerInAccessPath(int page, int rows, long id, Map<String, Object> params,
			Map<String, String> sorter);

	/**
	 * 查询未挂载给访问路径的网关服务器
	 *
	 * @param page
	 * @param rows
	 * @param id
	 * @param params
	 * @return
	 */
	public BocloudResult listServerOutAccessPath(int page, int rows, long id, Map<String, Object> params,
			Map<String, String> sorter);

	/**
	 * xsky用 更新物理机角色
	 *
	 * @param id
	 * @param params
	 * @param context
	 * @return
	 */
	default BocloudResult updateRole(Long id, String params, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * powervc用 查看服务器未管理的powervc云主机
	 *
	 * @param params
	 * @return
	 */
	default BocloudResult<List<CloudServer>> listUnmanagedPowervm(int page, int rows, List<Param> params,
			Map<String, String> sorter, boolean simple) {
		return new BocloudResult(false, "need implements");
	}

	BocloudResult<List<Server>> list(String params);

	BocloudResult<List<ServerConfig>> listByServerConfigs(JSONArray serverIds);

	/**
	 * powervc用 powervc添加未管理的云主机
	 *
	 * @param params
	 * @return
	 */
	default BocloudResult onboardPowervm(String params, RequestContext context) {
		return new BocloudResult(false, "need implements");

	}

	/**
	 * powervc用 powervc取消管理物理机上的云主机
	 *
	 * @param params
	 * @return
	 */
	default BocloudResult unmanagePowervm(String params, RequestContext context) {
		return new BocloudResult(false, "need implements");
	}

	/**
	 * hmc用 查询hmc下的宿主机
	 *
	 * @param hmcId
	 * @return
	 */
	default BocloudResult listByHmc(Long hmcId) {
		return new BocloudResult(false, "need implements");
	}

	default BocloudResult syncVmByHost(Long id, RequestContext context) {
		return null;
	}

	default BocloudResult listByVendorType(String conditionStr) {
		return new BocloudResult(false, "need implements");
	}

	BocloudResult ifaces(Pager pager,String ifaces, Long vendorId);

	BocloudResult ifaces( Pager pager);
}
