package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.PlatformServeDto;
import com.ym.mec.biz.service.PlatformServeService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author hgw
 * Created by 2021-12-03
 */
@RequestMapping("/platformServe")
@Api(tags = "平台服务管理")
@RestController
public class PlatformServeController extends BaseController {

    @Autowired
    private PlatformServeService platformServeService;

    @ApiOperation("添加平台服务")
    @PostMapping(value = "/add")
    @PreAuthorize("@pcs.hasPermissions('platformServe/add')")
    public Object addServe(@Valid @RequestBody PlatformServeDto dto) {
        platformServeService.addServe(dto);
        return succeed();
    }

    @ApiOperation("修改平台服务")
    @PostMapping(value = "/update")
    @PreAuthorize("@pcs.hasPermissions('platformServe/update')")
    public Object updateServe(@Valid @RequestBody PlatformServeDto dto) {
        platformServeService.updateServe(dto);
        return succeed();
    }

    @ApiOperation("删除平台服务")
    @GetMapping(value = "/delete/{id}")
    @PreAuthorize("@pcs.hasPermissions('platformServe/delete')")
    public Object deleteServe(@ApiParam(value = "平台服务ID", required = true) @PathVariable("id") Integer id) {
        platformServeService.deleteServe(id);
        return succeed();
    }

    @ApiOperation("分页查询")
    @GetMapping(value = "/queryPage")
    @PreAuthorize("@pcs.hasPermissions('platformServe/queryPage')")
    public Object queryPage(String search, Integer page, Integer rows) {
        return succeed(platformServeService.queryPage(search, page, rows));
    }

    @ApiOperation("查询单个服务的详情")
    @GetMapping(value = "/queryInfo/{id}")
    @PreAuthorize("@pcs.hasPermissions('platformServe/queryInfo')")
    public Object queryInfo(@ApiParam(value = "平台服务ID", required = true) @PathVariable("id") Integer id) {
        return succeed(platformServeService.queryInfo(id));
    }

    @ApiOperation("查询单个服务各付费模式详情")
    @GetMapping(value = "/queryModeDetail/{id}")
    @PreAuthorize("@pcs.hasPermissions('platformServe/queryModeDetail')")
    public Object queryModeDetail(@ApiParam(value = "平台服务ID", required = true) @PathVariable("id") Integer id) {
        return succeed(platformServeService.queryModeDetail(id));
    }


}
