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.TenantForbiddenConvert;
import com.wzj.soopin.member.domain.bo.TenantForbiddenBO;
import com.wzj.soopin.member.domain.po.TenantForbidden;
import com.wzj.soopin.member.domain.vo.TenantForbiddenVO;
import com.wzj.soopin.member.service.ITenantForbiddenService;
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("/system/tenant/forbidden")
@RequiredArgsConstructor
public class TenantForbiddenController {

    private final ITenantForbiddenService service;
    private final TenantForbiddenConvert convert;

    @Tag(name = "查询列表")
    @PostMapping("/list")
    public R<IPage<TenantForbiddenVO>> list(@RequestBody TenantForbiddenBO bo, @RequestBody Page page) {
        Page<TenantForbidden> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }

    @Tag(name = "新增")
    @Log(title = "新增 ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody TenantForbiddenBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Tag(name = "详情")
    @GetMapping(value = "/{id}")
    public R<TenantForbiddenVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Tag(name = ("处理"))
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody TenantForbiddenBO bo) {
        service.save(convert.toPo(bo));
        return R.ok();
    }


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