package com.izouma.nineth.service;

import com.izouma.nineth.ApplicationTests;
import com.izouma.nineth.domain.MintMaterial;
import com.izouma.nineth.domain.MintOrder;
import com.izouma.nineth.domain.User;
import com.izouma.nineth.enums.PayMethod;
import com.izouma.nineth.enums.SandPayMethod;
import com.izouma.nineth.repo.MintMaterialRepo;
import com.izouma.nineth.repo.MintOrderRepo;
import com.izouma.nineth.repo.UserRepo;
import org.apache.commons.collections.CollectionUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

class MintOrderServiceTest extends ApplicationTests {

    @Autowired
    private MintOrderService mintOrderService;
    @Autowired
    private UserRepo         userRepo;
    @Autowired
    private MintOrderRepo    mintOrderRepo;
    @Autowired
    private MintMaterialRepo mintMaterialRepo;

    @Test
    void exchange() throws InterruptedException {
        mintOrderService.create(9972L, Arrays.asList(134607L, 132435L, 132433L));
        Thread.sleep(1000);
    }

    @Test
    void test() {
        mintOrderService.batchCancel();
    }

    @Test
    public void test1() {
        User user = userRepo.findByIdAndDelFalse(9972L).orElse(null);
        mintOrderService.create(user, Arrays.asList(151339L), 151155L, null);
    }

    @Test
    public void test2() {
        mintOrderService.mintNotify(151376L, PayMethod.ALIPAY, "xxx");
    }

    @Test
    public void test3() {
        List<MintOrder> all = mintOrderRepo.findAll();
        all.forEach(a -> {
            List<MintMaterial> material = a.getMaterial();
            if (CollectionUtils.isNotEmpty(material)) {
                material.forEach(m -> {
                    m.setOrderId(a.getId());
                    mintMaterialRepo.save(m);
                });
            }

        });
    }
}