package com.trade.client.salesorder.service.impl;

import com.trade.client.trade.salesorder.service.SalesOrderCService;
import com.trade.service.filestorage.enums.FileTypeEnum;
import com.trade.service.contract.service.ISFileTemplateService;
import com.trade.service.trade.salesorder.domain.SalesOrder;
import com.trade.service.trade.salesorder.domain.SalesOrderGoods;
import com.trade.service.trade.salesorder.dto.SalesOrderDTO;
import com.trade.service.trade.salesorder.vo.SalesOrderSearch;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
class SalesOrderCServiceTest {
    @Resource
    private SalesOrderCService salesOrderCService;

    @Resource
    private ISFileTemplateService fileTemplateService;

    @Test
    void printProformaInvoiceFTLFileType() {
        System.out.println(fileTemplateService.selectByCode("123").getFileType());
    }

    @Test
    void printProformaInvoiceFTLCode() {
        System.out.println(
                fileTemplateService.selectByFileType(FileTypeEnum.PROFORMA_INVOICE.getCode()).getTemplateCode());
    }

    @Test
    void salesOrderSaveTest() {
        SalesOrder salesOrder = new SalesOrder();
        //salesOrder.setId(2L);
        salesOrder.setAmount(new BigDecimal(1000001));
        salesOrder.setCustomerUserId(1L);
        salesOrder.setImporterId(1L);
        salesOrder.setSaleContractId(1L);
        SalesOrderDTO salesOrderDTO = new SalesOrderDTO();
        salesOrderDTO.setSalesOrder(salesOrder);
        List<SalesOrderGoods> salesOrderGoodsList = new ArrayList<>();
        SalesOrderGoods salesOrderGoods = new SalesOrderGoods();
        salesOrderGoods.setHsCode("123");
        salesOrderGoods.setName("我的测试2");
        salesOrderGoods.setVendorEntityNo("123456789012345678");
        salesOrderGoodsList.add(salesOrderGoods);
        salesOrderDTO.setSalesOrderGoodsList(salesOrderGoodsList);
        salesOrderCService.save(salesOrderDTO, false);
    }

    @Test
    void getDetailTest() {
        System.out.println(salesOrderCService.getDetail(2L, true).getSalesOrderGoodsList().size());
    }

    @Test
    void queryTest() {
        SalesOrderSearch salesOrderSearch = new SalesOrderSearch();
        salesOrderSearch.setCustomerUserId(1L);
        System.out.println(salesOrderCService.queryListBySearch(salesOrderSearch));
    }

}
