
package com.pavis.admin.controller.open;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.pavis.admin.common.controller.BaseController;
import com.pavis.admin.open.model.query.AppQuery;
import com.pavis.admin.open.model.req.AppReq;
import com.pavis.admin.open.model.resp.AppDetailResp;
import com.pavis.admin.open.model.resp.AppResp;
import com.pavis.admin.open.model.resp.AppSecretResp;
import com.pavis.admin.open.service.AppService;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;

/**
 * 应用管理 API
 *
 * 
 * 
 * @since 2024/10/17 16:03
 */
@Tag(name = "应用管理 API")
@RestController
@RequiredArgsConstructor
@CrudRequestMapping(value = "/open/app", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE, Api.EXPORT})
public class AppController extends BaseController<AppService, AppResp, AppDetailResp, AppQuery, AppReq> {

    @Operation(summary = "获取密钥", description = "获取应用密钥")
    @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
    @SaCheckPermission("open:app:secret")
    @GetMapping("/{id}/secret")
    public AppSecretResp getSecret(@PathVariable Long id) {
        return baseService.getSecret(id);
    }

    @Operation(summary = "重置密钥", description = "重置应用密钥")
    @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
    @SaCheckPermission("open:app:resetSecret")
    @PatchMapping("/{id}/secret")
    public void resetSecret(@PathVariable Long id) {
        baseService.resetSecret(id);
    }
}