package cn.newfeifan.mall.module.trade.controller.app.shopsettlement;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

import cn.newfeifan.mall.module.trade.controller.app.shopsettlement.vo.*;
import cn.newfeifan.mall.module.trade.dal.dataobject.shopsettlement.ShopSettlementDO;
import cn.newfeifan.mall.module.trade.service.shopsettlement.ShopSettlementService;

@Tag(name = "用户 APP - 订单结算信息表，记录店铺的结算信息")
@RestController
@RequestMapping("/trade/shop-settlement")
@Validated
public class AppShopSettlementController {

    @Resource
    private ShopSettlementService shopSettlementService;

    @PostMapping("/create")
    @Operation(summary = "创建订单结算信息表，记录店铺的结算信息")
    public CommonResult<Long> createShopSettlement(@Valid @RequestBody AppShopSettlementSaveReqVO createReqVO) {
        return success(shopSettlementService.createShopSettlement(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新订单结算信息表，记录店铺的结算信息")
    public CommonResult<Boolean> updateShopSettlement(@Valid @RequestBody AppShopSettlementSaveReqVO updateReqVO) {
        shopSettlementService.updateShopSettlement(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除订单结算信息表，记录店铺的结算信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteShopSettlement(@RequestParam("id") Long id) {
        shopSettlementService.deleteShopSettlement(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得订单结算信息表，记录店铺的结算信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppShopSettlementRespVO> getShopSettlement(@RequestParam("id") Long id) {
        ShopSettlementDO shopSettlement = shopSettlementService.getShopSettlement(id);
        return success(BeanUtils.toBean(shopSettlement, AppShopSettlementRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得订单结算信息表，记录店铺的结算信息分页")
    public CommonResult<PageResult<AppShopSettlementRespVO>> getShopSettlementPage(@Valid AppShopSettlementPageReqVO pageReqVO) {
        PageResult<ShopSettlementDO> pageResult = shopSettlementService.getShopSettlementPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppShopSettlementRespVO.class));
    }

}