package cn.iocoder.yudao.module.configure.controller.admin.unitemplate;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.configure.controller.admin.unitemplate.vo.*;
import cn.iocoder.yudao.module.configure.service.unitemplate.UniTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 小程序模板")
@RestController
@RequestMapping("/configure/uni-template")
@Validated
public class UniTemplateController {

    @Resource
    private UniTemplateService uniTemplateService;

    @PostMapping("/createStandardTemplate")
    @ApiOperation("创建标准小程序模板")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:create')")
    public CommonResult<Long> createUniTemplate(@Valid @RequestBody UniTemplateCreateReqVO createReqVO) {
        return success(uniTemplateService.createUniTemplate(createReqVO));
    }

    @PostMapping("/createCustomizeTemplate")
    @ApiOperation("创建自定义小程序模板")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:create')")
    public CommonResult<Long> createCustomizeTemplate(@Valid @RequestBody UniTemplateCreateCustomizeReqVO createReqVO) {
        return success(uniTemplateService.createUniTemplate(createReqVO));
    }

    @PutMapping("/updateStandardTemplate")
    @ApiOperation("更新标准小程序模板")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:update')")
    public CommonResult<Boolean> updateUniTemplate(@Valid @RequestBody UniTemplateUpdateReqVO updateReqVO) {
        uniTemplateService.updateUniTemplate(updateReqVO);
        return success(true);
    }

    @PutMapping("/updateCustomizeTemplate")
    @ApiOperation("更新自定义小程序模板")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:update')")
    public CommonResult<Boolean> updateCustomizeTemplate(@Valid @RequestBody UniTemplateUpdateCustomizeReqVO updateReqVO) {
        uniTemplateService.updateUniTemplate(updateReqVO);
        return success(true);
    }


    @DeleteMapping("/delete")
    @ApiOperation("删除小程序模板")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:uni-template:delete')")
    public CommonResult<Boolean> deleteUniTemplate(@RequestParam("id") Long id) {
        uniTemplateService.deleteUniTemplate(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得小程序模板")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:uni-template:query')")
    public CommonResult<UniTemplateRespVO> getUniTemplate(@RequestParam("id") Long id) {
        return success(uniTemplateService.getUniTemplate(id));
    }

    @GetMapping("/page")
    @ApiOperation("获得小程序模板分页")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:query')")
    public CommonResult<PageResult<UniTemplateRespVO>> getUniTemplatePage(@Valid UniTemplatePageReqVO pageVO) {
        return success(uniTemplateService.getUniTemplatePage(pageVO));
    }

    @GetMapping("/options")
    @ApiOperation("获得小程序模板分页")
    @PreAuthorize("@ss.hasPermission('configure:uni-template:query')")
    public CommonResult<List<UniTemplateOptionVO>> getOptions() {
        return success(uniTemplateService.getOptions());
    }

}
