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

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.ims.entity.resource.Icon;
import com.bocloud.ims.interfaces.resource.ResourceIconService;
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;

/**
 * 镜像图标controller
 *
 * @author lyy
 * @Version 1.0
 * @since 2017年10月26日
 */
@RestController
@RequestMapping("/v1/resources/icons")
@Api(value = "图标管理", tags = "图标管理")
public class ResourceIconController {
    @Autowired
    private ResourceIconService resourceIconService;

    /**
     * 新增
     *
     * @param icon
     * @param context
     * @return
     */
    @ApiOperation(tags={"CMC","CSC"},value = "创建镜像图标",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "资源图标", operation = "创建镜像图标")
    @PostMapping
    public BocloudResult<Icon> create(@RequestBody Icon icon,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return resourceIconService.create(icon, context);
    }

    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags={"CMC","CSC"},value = "删除图标",  httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "资源图标", operation = "删除镜像图标")
    @DeleteMapping("/{id}")
    public BocloudResult<String> remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return resourceIconService.remove(id);
    }

    /**
     * 列表展示
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags={"CMC","CSC"},value = "查询图标",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "资源图标", operation = "查看镜像图标列表")
    @GetMapping
    public BocloudResult<GridBean<Icon>> list(Pager pager) {
        return resourceIconService.list(pager);
    }
}
