package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.system.dto.MiniAppPagesDTO;
import com.czg.system.service.MiniAppPageService;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序页面
 *
 * @author GYJoker
 */
@RestController
@RequestMapping("/admin/miniAppPages")
public class MiniAppPagesController {

    @Resource
    private MiniAppPageService miniAppPageService;

    /**
     * 新增小程序页面
     */
    @PostMapping
    @SaAdminCheckPermission(parentName = "小程序页面",value = "miniAppPages:add", name = "小程序页面添加")
    public CzgResult<Long> insertMiniAppPage(@RequestBody @Validated({InsertGroup.class}) MiniAppPagesDTO pagesDTO) {
        return miniAppPageService.insertMiniAppPage(pagesDTO);
    }

    /**
     * 修改小程序页面
     */
    @PutMapping
    @SaAdminCheckPermission(parentName = "小程序页面",value = "miniAppPages:update", name = "小程序页面修改")
    public CzgResult<Boolean> updateMiniAppPage(@RequestBody @Validated({UpdateGroup.class}) MiniAppPagesDTO pagesDTO) {
        return miniAppPageService.updateMiniAppPage(pagesDTO);
    }

    /**
     * 删除小程序页面
     * @param id 小程序页面主键
     */
    @DeleteMapping("{id}")
    @SaAdminCheckPermission(parentName = "小程序页面",value = "miniAppPages:delete", name = "小程序页面删除")
    public CzgResult<Boolean> deleteMiniAppPage(@PathVariable Long id) {
        return miniAppPageService.deleteMiniAppPageById(id);
    }

    /**
     * 查询小程序页面 分页
     * @param name 小程序页面名称
     * @param path 小程序页面路径
     * @param status 小程序页面状态 -1 查全部 1 启用 0 禁用
     */
    @GetMapping("page")
//    @SaAdminCheckPermission(parentName = "小程序页面",value = "miniAppPages:page", name = "小程序页面分页")
    public CzgResult<Page<MiniAppPagesDTO>> getMiniAppPage(String name, String path, Integer status) {
        return miniAppPageService.getMiniAppPage(name, path, status);
    }
}
