package com.sonic.lion.controller.mock;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.lion.domain.input.SubChargeProductListInput;
import com.sonic.lion.domain.output.ChargeProductConfigOutput;
import com.sonic.lion.domain.output.EnabledPayChannelOutput;
import com.sonic.lion.domain.output.SubProductListOutput;
import com.sonic.lion.domain.req.PrePaymentReq;
import com.sonic.lion.domain.resp.BuffCheckoutResp;
import com.sonic.lion.service.ChargeProductConfigService;
import com.sonic.lion.service.CheckOutService;
import com.sonic.lion.service.PayChargeService;
import com.sonic.lion.service.PayConfigService;
import com.sonic.sdk.api.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: code
 * @date: 2025/06/01
 * @Description:
 * @version: 1.0.0
 */
@Slf4j
@RestController
public class MockController {

    @Autowired
    private CheckOutService checkOutService;
    @Autowired
    private PayChargeService payChargeService;
    @Autowired
    private PayConfigService payConfigService;
    @Autowired
    private ChargeProductConfigService chargeProductConfigService;

    @IgnoreAuth
    @ApiOperation(value = "下单并结账", tags = "Mock-接口")
    @PostMapping("/mock/pay/trade/checkout/v2")
    public Result<BuffCheckoutResp> checkout(@RequestBody @Validated PrePaymentReq req) {
        BuffCheckoutResp result = checkOutService.checkout(req);
        return Result.success(result);
    }

    @IgnoreAuth
    @ApiOperation(value = "充值可用的支付渠道列表", tags = "支付相关配置")
    @PostMapping("/mock/pay/config/enabled-pay-channel")
    public Result<EnabledPayChannelOutput> enabledPayChannel(Session session) {
        session.setUserId(1L);
        return Result.success(payConfigService.enabledPayChannel(session.getUserId()));
    }

    @IgnoreAuth
    @ApiOperation(value = "充值档位列表", tags = "支付相关配置")
    @PostMapping("/mock/pay/config/charge-product-list")
    public Result<ChargeProductConfigOutput> chargeList(@RequestBody @Validated SubChargeProductListInput input, Session session) {
        session.setUserId(1L);
        ChargeProductConfigOutput output = chargeProductConfigService.getRechargeLevelConfig(session.getUserId(), input.getPlatform(), input.getVersion());
        return Result.success(output);
    }

    @IgnoreAuth
    @ApiOperation(value = "订阅档位列表", tags = "支付相关配置")
    @PostMapping("/mock/pay/config/sub-product-list")
    public Result<List<SubProductListOutput>> subProductList(@RequestBody @Validated SubChargeProductListInput input) {
        return Result.success(payChargeService.subProductList(input));
    }

}
