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

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.ResultTools;
import com.bocloud.ims.entity.resource.CloudServer;
import com.bocloud.ims.entity.resource.NatGatewaySnatRule;
import com.bocloud.ims.entity.resource.Subnet;
import com.bocloud.ims.interfaces.resource.NatGatewaySnatRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

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.*;

@RestController
@RequestMapping("/v1/natgateway/snat/rule")
@Api(value = "nat网关snat规则", tags = "nat网关snat规则")
public class NatGatewaySnatRuleController {

	@Autowired
	private NatGatewaySnatRuleService service;

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询nat网关snat规则列表",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "查询nat网关snat规则列表")
	@GetMapping
	public BocloudResult<GridBean<NatGatewaySnatRule>> list(Pager pager,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return service.list(pager, context);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "创建nat网关snat规则",  httpMethod = "POST")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "创建nat网关snat规则")
	@PostMapping
	public BocloudResult create(@RequestBody NatGatewaySnatRule snatRule,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return service.create(snatRule, context);

	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "nat网关snat规则",  httpMethod = "DELETE")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "删除nat网关snat规则")
	@DeleteMapping("/{id}")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return service.remove(id, context);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "nat网关snat规则",  httpMethod = "PUT")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "更新nat网关snat规则")
	@PutMapping(value = "/{id}")
	public BocloudResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody NatGatewaySnatRule gateway,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != gateway) {
			if (gateway.getId() == null) {
				gateway.setId(id);
			}
			return service.modify(gateway, context);
		} else {
			return ResultTools.formatErrResult();
		}
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查看nat网关snat规则",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "查看nat网关snat规则")
	@GetMapping("/{id}")
	public BocloudResult<NatGatewaySnatRule> detail(@PathVariable(value = Common.ID) Long id) {
		return service.detail(id);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查看nat网关snat规则可用子网",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "查看nat网关snat规则可用子网")
	@GetMapping("/subnet")
	public BocloudResult<List<Subnet>> listSubnets(@RequestParam(value = Common.PARAMS, required = false) String params) {
		return service.listSubnet(params);
	}

	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查看nat网关snat规则可用ecs实例",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "nat网关snat规则", operation = "查看nat网关snat规则可用ecs实例")
	@GetMapping("/ecs")
	public BocloudResult<List<CloudServer>> listEcs(@RequestParam(value = Common.PARAMS, required = false) String params) {
		return service.listEcs(params);
	}
}
