package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.config.log.Log;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.tenant.entity.dto.SceneDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.UserLibDto;
import cn.hanghui.outapi.platform.tenant.entity.enums.BusinessTypeEnum;
import cn.hanghui.outapi.platform.tenant.entity.enums.LogTagEnum;
import cn.hanghui.outapi.platform.tenant.service.SceneService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "场景、用户库管理")
@RestController
@RequestMapping("/api/v1/scene")
@AllArgsConstructor(onConstructor_ = @Autowired)
public class SceneController {

    private SceneService sceneService;

    @ApiOperation(value = "添加或编辑场景")
    @PostMapping("/add")
    @Log(tag = LogTagEnum.SCENE,title = "添加/编辑场景",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> addScene(@RequestBody SceneDto dto) {
        return sceneService.addScene(dto);
    }

    @ApiOperation(value = "删除场景")
    @GetMapping("/del/{id}")
    @Log(tag = LogTagEnum.SCENE,title = "删除场景",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> delScene(@PathVariable(value = "id") @ApiParam(value = "id", required = true) Long id) {
        return sceneService.delScene(id);
    }

    @ApiOperation(value = "查询场景列表（分页）")
    @PostMapping("/page")
    public RestResult<IPage<SceneDto>> pageScene(@RequestBody SceneDto dto) {

        return sceneService.pageScene(dto);
    }

    @ApiOperation(value = "添加或编辑用户库")
    @PostMapping("/userlib/add")
    @Log(tag = LogTagEnum.USERLIB,title = "添加/编辑用户库",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> addUserLib(@RequestBody UserLibDto dto) {
        return sceneService.addUserLib(dto);
    }

    @ApiOperation(value = "删除用户库")
    @GetMapping("/userlib/del/{id}")
    @Log(tag = LogTagEnum.USERLIB,title = "删除用户库",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> delUserLib(@PathVariable(value = "id") @ApiParam(value = "id", required = true) Long id) {
        return sceneService.delUserLib(id);
    }
    @ApiOperation(value = "用户库列表")
    @GetMapping("/userlib/list")
    public RestResult<List<UserLibDto>> serLibList() {

        return sceneService.serLibList();
    }
    @ApiOperation(value = "查询用户库列表（分页）")
    @PostMapping("/userlib/page")
    public RestResult<IPage<UserLibDto>> pageUserLib(@RequestBody UserLibDto dto) {

        return sceneService.pageUserLib(dto);
    }


}
