package com.seer.teach.user.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.user.admin.request.AdminUpdateReq;
import com.seer.teach.user.admin.service.AdminUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商家端用户管理控制器
 * </p>
 *
 * @author Captain
 * @since 2025-05-14
 */
@RestController
@RequestMapping("/merchant")
@Tag(name = "商户端 - 用户管理")
@Validated
@RequiredArgsConstructor
public class MerchantUserController {

    private final AdminUserService adminUserService;

    /**
     * 商家修改密码
     *
     * @param params 密码修改参数
     * @return 操作结果
     */
    @PutMapping("/password")
    @LogPrint
    @SaCheckLogin(type = StpUtil.TYPE)
    @Operation(summary = "商家修改密码")
    @SaCheckPermission("merchant:user:password:update")
    public ResultBean<Boolean> updatePassword(@RequestBody @Validated AdminUpdateReq params) {
        // 获取当前登录用户ID
        Integer userId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(adminUserService.resetPassword(params, userId));
    }
}