package com.izouma.nineth.service;

import com.izouma.nineth.ApplicationTests;
import com.izouma.nineth.domain.*;
import com.izouma.nineth.repo.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;

class AssetServiceTest extends ApplicationTests {
    @Autowired
    private OrderRepo         orderRepo;
    @Autowired
    private BlindBoxItemRepo  blindBoxItemRepo;
    @Autowired
    private AssetService      assetService;
    @Autowired
    private CollectionRepo    collectionRepo;
    @Autowired
    private UserRepo          userRepo;
    @Autowired
    private CollectionService collectionService;
    @Autowired
    private AssetMintService  assetMintService;
    @Autowired
    private AssetRepo         assetRepo;

    @Test
    void createAsset() {
        BlindBoxItem item = blindBoxItemRepo.findById(1860L).get();
        Order order = orderRepo.findById(1922L).get();
    }

    @Test
    void cancelConsignment() {
        assetService.cancelConsignment(1209L);
    }

    @Test
    void testCancelConsignment() {
    }

    @Test
    public void testLock() throws InterruptedException {
        assetService.testLock("123", "ddd");
    }

    @Test
    public void testCreateAsset() {
        Order order = orderRepo.findById(4618L).get();
        Collection collection = collectionRepo.findById(order.getCollectionId()).get();
        BlindBoxItem blindBoxItem = blindBoxItemRepo.findById(4250L).get();
        User user = userRepo.findById(order.getUserId()).get();
        assetService.createAsset(blindBoxItem, user, order.getId(), order.getPrice(), "出售", 1);
    }

    @Test
    public void setHistory() {
        assetService.setHistory();
    }

    @Test
    public void cancelCon() {
        for (Asset asset : assetRepo.findNoAccount()) {
            try {
                assetService.cancelConsignment(asset.getId());
            } catch (Exception e) {

            }
        }
    }


    @Test
    public void stat() {
        Map<User, Integer> match = assetService.holdQuery(Arrays.asList(
                        "【熊猫柯斯】-虎虎生威"),
                LocalDateTime.of(2021, 12, 31, 9, 59, 59),
                LocalDateTime.of(2021, 12, 31, 10, 0, 0));
        System.out.println("用户ID,昵称,手机,持有套数");
        for (Map.Entry<User, Integer> e : match.entrySet()) {
            User user = e.getKey();
            System.out.printf("%d,%s,%s,%d%n", user.getId(), user.getNickname(), user.getPhone(), e.getValue());
        }

    }

    @Test
    public void userHistory() {
        assetService.userHistory(44L, 1, Pageable.unpaged());
    }

    @Test
    public void test() {
        assetService.ranking(439L, 20).forEach(System.out::println);
    }
}