package com.snack.server.module.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.snack.server.common.Result;
import com.snack.server.module.file.enums.FileBizTypeEnum;
import com.snack.server.module.file.service.FileService;
import com.snack.server.module.file.vo.FileUploadVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 管理员头像上传
 */
@Tag(name = "管理员头像")
@RestController
@RequestMapping("/api/admin/avatar")
@RequiredArgsConstructor
public class AdminAvatarController {

    private final FileService fileService;

    @Operation(summary = "上传当前管理员头像")
    @SaCheckLogin
    @PostMapping("/upload")
    public Result<FileUploadVO> upload(@RequestParam("file") MultipartFile file) {
        Long uploaderId = cn.dev33.satoken.stp.StpUtil.getLoginIdAsLong();
        return Result.ok(fileService.uploadWithUploader(
                file, FileBizTypeEnum.ADMIN_AVATAR.getCode(), uploaderId));
    }
}
