package com.bocloud.ims.booter.controller.resource.hmc;

import com.alibaba.fastjson.JSONObject;
import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.JSONTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.resource.hmc.HmcProfile;
import com.bocloud.ims.interfaces.resource.hmc.HmcProfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/hmc/partitions/{partitionId}/profiles")
@Api(value = "HMC概要文件", tags = "HMC概要文件")
public class HmcProfileController {
	@Autowired
	private HmcProfileService hmcProfileService;

	/**
	 * 列表
	 *
	 * @param pager
	 *            分页参数
	 * @param context
	 *            操作者信息
	 * @return 数据结果集
	 */
	@Log(module = BoCloudService.IMS, target = "HMC概要文件", operation = "查询")
	@RequestMapping(method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询",  httpMethod = "GET")
	public BocloudResult<GridBean<List<HmcProfile>>> list(Pager pager) {
		return hmcProfileService.list(pager);
	}

	/**
	 * 添加logical partition
	 * 
	 * @param profile
	 * @return 添加结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC概要文件", operation = "创建")
	@RequestMapping(method = { RequestMethod.POST })
	@ApiOperation(tags={"CMC","CSC"},value = "创建",  httpMethod = "POST")
	public BocloudResult create(@RequestBody HmcProfile profile,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcProfileService.create(profile, context);
	}

	/**
	 * 修改概要文件
	 *
	 * @param profile
	 *            逻辑分区属性信息的json字符串，在数据转换时会发生异常，对外抛出400异常【Bad Request】
	 * @param id
	 *            需要修改的逻辑分区ID
	 */
	@Log(module = BoCloudService.IMS, target = "HMC概要文件", operation = "修改")
	@RequestMapping(value = "/{id}", method = { RequestMethod.PUT })
	@ApiOperation(tags={"CMC","CSC"},value = "修改",  httpMethod = "PUT")
	public BocloudResult modify(@RequestBody HmcProfile profile,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcProfileService.modify(profile, context);
	}

	/**
	 * 详细信息
	 * 
	 * @param id
	 * @return 操作结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC概要文件", operation = "详情")
	@RequestMapping(value = "/{id}", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "详情",  httpMethod = "GET")
	public BocloudResult<HmcProfile> detail(@PathVariable(value = Common.ID) Long id,
			@PathVariable(value = "partitionId", required = true) long partitionId) {
		return hmcProfileService.detail(id);
	}

	/**
	 * 删除概要文件
	 * 
	 * @param id
	 *            HMC概要文件 ID
	 * @return 操作结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC概要文件", operation = "删除")
	@RequestMapping(value = "/{id}", method = { RequestMethod.DELETE })
	@ApiOperation(tags={"CMC","CSC"},value = "删除",  httpMethod = "DELETE")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcProfileService.remove(id, context);
	}
}
