package com.app.service.order;

import com.app.Application;
import com.app.constant.SystemConstant;
import com.app.entity.order.OpenCourseRefund;
import com.app.util.JacksonUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)// 指定spring-boot的启动类
public class OpenCourseRefundServiceTest {

    @Autowired
    private OpenCourseRefundService service;

    /**
     * 功能描述：后台手动统一申请退课
     *
     * 1. 更改application.yml文件的环境为prod
     * spring:
     *   profiles:
     *     active: prod
     * 2. 调整RefundDto对象的入参。注意订单项id、账号id
     */
    @Test
    public void apply() {
        List<RefundDto> list = new ArrayList<>();
//        list.add(new RefundDto("664843325760602112", "后台手动统一申请退课", "617246469799280640", "1"));

        for (RefundDto refundDto : list) {
            String organId = SystemConstant.organId;
            OpenCourseRefund refund = service.apply(organId, refundDto.getOpenCourseOrderItemId(), refundDto.getRemarks(), refundDto.getAccountId(), refundDto.getWxmpFormId());
            log.info("退课申请成功：[{}]", JacksonUtil.toJSON(refund));
        }
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Accessors(chain = true)
    public class RefundDto {
        private String openCourseOrderItemId; // 订单项标识
        private String remarks; // 申请退课备注
        private String accountId = ""; // 账号标识（账号与订单项关联）
        private String wxmpFormId;
    }

}

