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

import com.bocloud.cmp.model.ContentLibraryParam;
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.contentlibrary.ContentLibrary;
import com.bocloud.ims.entity.resource.contentlibrary.ContentLibraryItem;
import com.bocloud.ims.interfaces.resource.contentlibrary.ContentLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * 内容库
 *
 * @author wangyu
 * @version 5.0.0-SNAPSHOT
 * @since 2021/2/26
 */
@Slf4j
@RestController
@RequestMapping("/v1/content/libraries")
@Api(value = "内容库管理", tags = "内容库管理")
public class ContentLibraryController {

    @Autowired
    private ContentLibraryService service;

    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取内容库列表")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "获取内容库列表")
    @GetMapping
    public BocloudResult<GridBean<ContentLibrary>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.list(pager, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取内容库模板列表")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "获取内容库模板列表")
    @GetMapping("/items")
    public BocloudResult<GridBean<ContentLibraryItem>> listItems(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.listItems(pager, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "通过ovf部署云主机")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "通过ovf部署云主机")
    @PostMapping("/deploy")
    public BocloudResult deploy(@RequestBody ContentLibraryParam contentLibraryParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.deploy(contentLibraryParam, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询内容库详情")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "查询内容库详情")
    @GetMapping("/{id}")
    public BocloudResult<ContentLibrary> detail(@PathVariable(Common.ID) Long id) {
        return service.detail(id);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询内容库模板详情")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "查询内容库模板详情")
    @GetMapping("/items/{id}")
    public BocloudResult<ContentLibraryItem> detailItem(@PathVariable(Common.ID) Long id) {
        return service.detailItem(id);
    }
    /** @Author: lxy
     * @Description: 修改内容库模板密码
     * @Date 2021/5/25 14:45
     * @Param id
     * @param password
     * @param context
     * @return com.bocloud.common.model.BocloudResult
     * @throws:
     **/
    @ApiOperation(tags = { "CMC", "CSC" }, value = "维护内容库模板密码", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "内容库", operation = "维护内容库模板密码")
    @GetMapping("/item/{id}/accounts")
    public BocloudResult modifyAccount(@PathVariable(value = Common.ID) Long id,
                                       @RequestParam(value = Common.PSD, required = false) String password, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.modifyAccount(id, password, context);
    }

}
