package com.seer.teach.mall.app.order.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.mall.app.order.service.IAppAfterSaleService;
import com.seer.teach.mall.request.AfterSalePageReq;
import com.seer.teach.mall.request.AppAfterSaleCreateReq;
import com.seer.teach.mall.request.AppAfterSaleDeliveryReq;
import com.seer.teach.mall.response.AfterSaleResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/user/after-sale")
@Tag(name = "APP - 交易售后")
@Validated
@RequiredArgsConstructor
@EncryptionAnnotation
@DecryptionAnnotation
public class AppAfterSaleController {

    private final IAppAfterSaleService appAfterSaleService;

    @PostMapping(value = "/page")
    @SaCheckPermission("app:after-sale:page")
    @Operation(summary = "获得售后分页")
    public ResultBean<PageListBean<AfterSaleResp>> getAfterSalePage(@RequestBody AfterSalePageReq pageReqVO) {
        return ResultBean.success(appAfterSaleService.queryPageList(pageReqVO));
    }

    @GetMapping(value = "/get")
    @SaCheckPermission("app:after-sale:get")
    @Operation(summary = "获得售后订单")
    public ResultBean<AfterSaleResp> getAfterSale(@RequestParam("id") Integer id) {
        return ResultBean.success(appAfterSaleService.getAfterSale(id));
    }

    @PostMapping(value = "/create")
    @SaCheckPermission("app:after-sale:create")
    @Operation(summary = "申请售后")
    public ResultBean<Boolean> createAfterSale(@RequestBody AppAfterSaleCreateReq createReqVO) {
        return ResultBean.success(appAfterSaleService.createAfterSale(createReqVO));
    }

    @PutMapping(value = "/delivery")
    @SaCheckPermission("app:after-sale:delivery")
    @Operation(summary = "退回货物")
    public ResultBean<Boolean> deliveryAfterSale(@RequestBody AppAfterSaleDeliveryReq deliveryReq) {
        return ResultBean.success(appAfterSaleService.deliveryAfterSale(deliveryReq));
    }

    @PutMapping(value = "/cancel")
    @SaCheckPermission("app:after-sale:cancel")
    @Operation(summary = "取消售后")
    public ResultBean<Boolean> cancelAfterSale(@RequestParam("id") Integer id) {
        return ResultBean.success(appAfterSaleService.cancelAfterSale(id));
    }

    @DeleteMapping(value = "/delete")
    @SaCheckPermission("app:after-sale:delete")
    @Operation(summary = "删除售后")
    public ResultBean<Boolean> deleteAfterSale(@RequestParam("id") Integer id) {
        return ResultBean.success(appAfterSaleService.deleteAfterSale(id));
    }
}
