package com.gxwebsoft.shop.controller;

import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.ShopVerifyUser;
import com.gxwebsoft.shop.param.ShopVerifyUserParam;
import com.gxwebsoft.shop.service.ShopVerifyUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单核销人管理控制器
 *
 * @author xm
 * @since 2026-05-25 17:13:01
 */
@Tag(name = "订单核销人管理管理")
@RestController
@RequestMapping("/api/shop/shop-verify-user")
public class ShopVerifyUserController extends BaseController {
    @Resource
    private ShopVerifyUserService shopVerifyUserService;

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:list')")
    @Operation(summary = "分页查询订单核销人管理")
    @GetMapping("/page")
    public ApiResult<PageResult<ShopVerifyUser>> page(ShopVerifyUserParam param) {
        // 使用关联查询
        return success(shopVerifyUserService.pageRel(param));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:list')")
    @Operation(summary = "查询全部订单核销人管理")
    @GetMapping()
    public ApiResult<List<ShopVerifyUser>> list(ShopVerifyUserParam param) {
        // 使用关联查询
        return success(shopVerifyUserService.listRel(param));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:list')")
    @Operation(summary = "根据id查询订单核销人管理")
    @GetMapping("/{id}")
    public ApiResult<ShopVerifyUser> get(@PathVariable("id") Integer id) {
        // 使用关联查询
        return success(shopVerifyUserService.getByIdRel(id));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:list')")
    @Operation(summary = "根据用户ID查询订单核销人管理")
    @GetMapping("/getByUserId")
    public ApiResult<ShopVerifyUser> getByUserId(@RequestParam("userId") Integer userId) {
        return success(shopVerifyUserService.getInfo(userId));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:save')")
    @OperationLog
    @Operation(summary = "添加订单核销人管理")
    @PostMapping()
    public ApiResult<Boolean> save(@RequestBody ShopVerifyUser shopVerifyUser) {
        return success(shopVerifyUserService.saveInfo(shopVerifyUser));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:update')")
    @Operation(summary = "修改订单核销人管理")
    @PutMapping()
    public ApiResult<?> update(@RequestBody ShopVerifyUser shopVerifyUser) {
        if (shopVerifyUserService.updateById(shopVerifyUser)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @Operation(summary = "修改订单核销人开启状态")
    @PutMapping("/updateStatus")
    public ApiResult<Boolean> updateStatus(@RequestParam("id") Integer id) {
        return success(shopVerifyUserService.updateStatus(id));
    }

    @Operation(summary = "修改订单核销人核销权限")
    @PutMapping("/updateVerifyFlag")
    public ApiResult<Boolean> updateVerifyFlag(@RequestParam("id") Integer id) {
        return success(shopVerifyUserService.updateVerifyFlag(id));
    }

//    @PreAuthorize("hasAuthority('shop:shopVerifyUser:remove')")
    @OperationLog
    @Operation(summary = "删除订单核销人管理")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (shopVerifyUserService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }


}
