package com.ruoyi.cai.controller.app;

import com.ruoyi.cai.dto.app.query.AlbumAddReq;
import com.ruoyi.cai.dto.app.query.AlbumResetReq;
import com.ruoyi.cai.dto.app.query.IdRes;
import com.ruoyi.cai.dto.app.query.UserUpdateReq;
import com.ruoyi.cai.dto.app.vo.CurrentUserInfoVo;
import com.ruoyi.cai.manager.CurrentUserManager;
import com.ruoyi.cai.service.UserAlbumService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
@Tag(name = "用户相关接口")
public class UserAppController {
    @Autowired
    private CurrentUserManager currentUserManager;
    @Autowired
    private UserAlbumService userAlbumService;

    @GetMapping("/info")
    @Operation(summary = "当前用户信息")
    public R<CurrentUserInfoVo> currentInfo(){
        return R.ok(currentUserManager.currentInfo());
    }

    @PostMapping("/update")
    @Operation(summary = "修改当前用户信息")
    public R<Boolean> userUpdate(@RequestBody UserUpdateReq res){
        return R.ok(currentUserManager.userUpdate(res));
    }

    @PostMapping("/album/del")
    @Operation(summary = "删除相册")
    public R<Boolean> userAlbumDel(@RequestBody IdRes res){
        return R.ok(userAlbumService.removeAlbum(res.getId()));
    }

    @PostMapping("/album/add")
    @Operation(summary = "新增相册")
    public R<Boolean> userAlbumAdd(@RequestBody AlbumAddReq res){
        res.setUserId(LoginHelper.getUserId());
        return R.ok(userAlbumService.addAlbum(res));
    }

    @PostMapping("/album/reset")
    @Operation(summary = "重排序相册",hidden = true)
    public R<Boolean> userAlbumAdd(@RequestBody List<AlbumResetReq> res){
        return R.ok(userAlbumService.resetAlbum(res,LoginHelper.getUserId()));
    }

}
