package com.clx.performance.controller.pc.loan.owner;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.param.pc.loan.carrier.PageOwnerRepaymentOfOwner;
import com.clx.performance.param.pc.loan.owner.ExportPaymentApplicationFormParam;
import com.clx.performance.service.loan.OwnerRepaymentService;
import com.clx.performance.vo.pc.loan.carrier.OwnerRepaymentVO;
import com.clx.performance.vo.pc.loan.owner.OwnerCashierInfoVO;
import com.clx.performance.vo.pc.loan.owner.OwnerOrderPaymentDetailVO;
import com.clx.performance.vo.pc.loan.owner.OwnerTransferPaymentDetailVO;
import com.msl.common.base.PageData;
import com.msl.common.convertor.aspect.UnitCovert;
import com.msl.common.result.Result;
import com.msl.user.data.UserSessionData;
import com.msl.user.utils.TokenUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping(value="/pc/owner/ownerRepayment")
@Validated
@Tag(name = "货主端-资金管理（货主借款账户管理（申请借款））")
@AllArgsConstructor
public class OwnerRepaymentController {

    private final OwnerRepaymentService ownerRepaymentService;


    @Operation(summary = "还款列表",description = "<br>By:刘海泉")
    @PostMapping("/pageOwnerRepayment")
    @UnitCovert(param = false)
    public Result<PageData<OwnerRepaymentVO>> pageOwnerRepayment(@RequestBody @Validated PageOwnerRepaymentOfOwner param) {
        UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
        param.setOwnerUserNo(String.valueOf(loginUserInfo.getCompanyNo()));
        IPage<OwnerRepaymentVO> page = ownerRepaymentService.pageOwnerRepaymentOfOwner(param);
        return Result.page(page.getRecords(), page.getTotal(), page.getPages());
    }


    @Operation(summary = "收银台信息",description = "<br>By:刘海泉")
    @GetMapping("/getCashierInfo")
    @UnitCovert(param = false)
    public Result<OwnerCashierInfoVO> getCashierInfo(@Param("id") @NotNull(message = "id不能为空") Integer id) {
        OwnerCashierInfoVO vo = ownerRepaymentService.getCashierInfo(id);
        return Result.ok(vo);
    }


    @Operation(summary = "订单支付详情",description = "<br>By:刘海泉")
    @GetMapping("/getOrderPaymentDetail")
    @UnitCovert(param = false)
    public Result<OwnerOrderPaymentDetailVO> getOrderPaymentDetail(@Param("id") @NotNull(message = "id不能为空") Integer id) {
        OwnerOrderPaymentDetailVO vo = ownerRepaymentService.getOrderPaymentDetail(id);
        return Result.ok(vo);
    }

    @Operation(summary = "转账支付详情",description = "<br>By:刘海泉")
    @GetMapping("/getTransferPaymentDetail")
    @UnitCovert(param = false)
    public Result<OwnerTransferPaymentDetailVO> getTransferPaymentDetail(@Param("id") @NotNull(message = "id不能为空") Integer id) {
        OwnerTransferPaymentDetailVO vo = ownerRepaymentService.getTransferPaymentDetail(id);
        return Result.ok(vo);
    }


    @Operation(summary = "生成付款申请单",description = "<br>By:刘海泉")
    @PostMapping("/savePaymentApplicationForm")
    public Result<String> savePaymentApplicationForm(@RequestBody @Validated ExportPaymentApplicationFormParam param) {
        String url = ownerRepaymentService.savePaymentApplicationForm(param);
        return Result.ok(url);
    }

    @Operation(summary = "转账支付-还款短信", description = "<br>By:姜文业")
    @GetMapping("/sendPaymentSms")
    public Result<String> sendPaymentSms(@RequestParam("mobile") @NotBlank(message = "通知的手机号码不能为空") String mobile,
                                                    @Param("repaymentNo") @NotNull(message = "还款单号不能为空") Long repaymentNo) {
        String token = ownerRepaymentService.sendPaymentSms(mobile,repaymentNo);
        return Result.ok(token);
    }

    @Operation(summary = "订单支付短信", description = "<br>By:姜文业")
    @GetMapping("/sendOrderPaySms")
    public Result<String> sendOrderPaySms(@RequestParam("mobile") @NotBlank(message = "通知的手机号码不能为空") String mobile,
                                         @Param("payee") @NotBlank(message = "收款方不能为空") String payee,
                                          @Param("payeeAccount") @NotBlank(message = "收款账户不能为空") String payeeAccount) {
        String token = ownerRepaymentService.sendOrderPaySms(mobile,payee,payeeAccount);
        return Result.ok(token);
    }



}
