
package com.wzj.soopin.member.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.convert.MemberForbiddenConvert;
import com.wzj.soopin.member.domain.bo.MemberForbiddenBO;
import com.wzj.soopin.member.domain.po.MemberForbidden;
import com.wzj.soopin.member.domain.vo.MemberForbiddenVO;
import com.wzj.soopin.member.service.IMemberForbiddenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;

/**
 * 用户封禁
 */
@Tag(name = "用户封禁")
@RestController
@RequestMapping("/ums/forbidden")
@RequiredArgsConstructor
public class MemberForbiddenController {

    private final IMemberForbiddenService service;
    private final MemberForbiddenConvert convert;

    @Operation(summary = "查询用户封禁列表")
    @PostMapping("/list")
    public R<IPage<MemberForbiddenVO>> list(@RequestBody MemberForbiddenBO bo, @RequestBody Page page) {
        Page<MemberForbidden> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }

    @Operation(summary = "新增用户封禁")
    @Log(title = "新增用户封禁", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody MemberForbiddenBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Operation(summary = "获取用户封禁详情")
    @GetMapping(value = "/{id}")
    public R<MemberForbiddenVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Operation(summary = "修改用户封禁")
    @Log(title = "修改用户封禁", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody MemberForbiddenBO bo) {
        service.save(convert.toPo(bo));
        return R.ok();
    }


    @Operation(summary = "删除用户封禁")
    @Log(title = "删除用户封禁", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Object> remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }
}
