package cn.reghao.tnb.file.app.zoss.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.file.app.zoss.model.po.UserKey;
import cn.reghao.tnb.file.app.service.StoreConfigService;
import cn.reghao.tnb.file.app.zoss.service.UserKeyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-02-27 10:24:31
 */
@Tag(name = "oss key 接口")
@RestController
@RequestMapping("/api/oss/key")
public class UserKeyController {
    private final UserKeyService userKeyService;
    private final StoreConfigService storeConfigService;

    public UserKeyController(UserKeyService userKeyService, StoreConfigService storeConfigService) {
        this.userKeyService = userKeyService;
        this.storeConfigService = storeConfigService;
    }

    @Operation(summary = "oss key 页面", description = "N")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public String userKeyPage() {
        int ossUser = storeConfigService.getLocalOssUser();
        List<UserKey> list = userKeyService.getUserKeys(ossUser);
        return WebResult.success(list);
    }

    @Operation(summary = "重新生成  oss key", description = "N")
    @PostMapping(value = "/regenerate", produces = MediaType.APPLICATION_JSON_VALUE)
    public String regenerate() {
        int ossUser = storeConfigService.getLocalOssUser();
        userKeyService.regenerate(ossUser);
        return WebResult.success();
    }
}
