package com.wzj.soopin.transaction.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.transaction.convert.DivideConvert;
import com.wzj.soopin.transaction.domain.bo.DivideBO;
import com.wzj.soopin.transaction.domain.po.Divide;
import com.wzj.soopin.transaction.domain.vo.DivideVO;
import com.wzj.soopin.transaction.service.IDivideService;
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("/trans/divide")
@RequiredArgsConstructor
public class DivideController {

    private final IDivideService service;
    private final DivideConvert convert;


    @Tag(name = "查询列表")
    @PostMapping("/list")
    public R<IPage<DivideVO>> slist(@RequestBody DivideBO bo, @RequestBody Page page) {
        Page<Divide> 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 DivideBO bo) {
        return R.ok(service.save(bo));
    }

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



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


    @Tag(name = "根据订单id分账")
    @Log(title = "分账", businessType = BusinessType.DELETE)
    @PostMapping("/divide/{orderId}")
    public R divide(@PathVariable Long orderId) {
        service.divide(orderId);
        return R.ok();
    }



}
