package kr.co.jinwoosi.clfd.clfd.prod.service;

import kr.co.jinwoosi.clfd.conts.prod.model.Prod;
import kr.co.jinwoosi.clfd.conts.prod.model.ProdSearch;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

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

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
        "classpath:config/spring/context-datasource.xml",
        "classpath:config/spring/context-mybatis.xml",
        "classpath:config/spring/context-common.xml",
        "classpath:config/spring/context-transaction.xml"
})
public class ClfdProdServiceTest {

    @Autowired
    private ClfdProdService clfdProdService;

    @Test
    public void plusRcmdNoTest() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setProdId(1L);
        Prod prod = clfdProdService.select(prodSearch);
        clfdProdService.plusRcmdNo(prod);
        clfdProdService.update(prod);
    }

    @Test
    public void minusRcmdNoTest() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setProdId(1L);
        Prod prod = clfdProdService.select(prodSearch);
        clfdProdService.minusRcmdNo(prod);
        clfdProdService.update(prod);
    }

    @Test
    public void selectWithLikeTest() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setProdId(56L);
        Prod prod = clfdProdService.selectWithLike(prodSearch, 164L);
        System.out.println(prod);
    }
    @Test
    public void getProdTyTest() {
        clfdProdService.getProdTyCdDtlList().forEach(System.out::println);
    }

    @Test
    public void selectProdListTest() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setPagingYn(true);
        prodSearch.setStart(0);
        prodSearch.setLength(8);
        prodSearch.setSort("RCMD_NO");
        prodSearch.setSortOrd("DESC");

        List<Prod> prodList =  clfdProdService.selectList(prodSearch);
        System.out.println(prodList.size());
        for (Prod prod : prodList) {
            System.out.println(prod.getProdId() + ": " +prod.getRcmdNo());
        }
    }

    @Test
    public void selectProdListTest2() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setPagingYn(true);
        prodSearch.setSort("PROD_PRC");
        prodSearch.setSortOrd("DESC");
        prodSearch.setStart(0);
        prodSearch.setLength(100);
        List<String> prodTyList = new ArrayList<String>();
        prodSearch.setProdTyList(prodTyList);
        List<String> skTyList = new ArrayList<>();
        prodSearch.setSkTyList(skTyList);
        List<Prod> prodList =  clfdProdService.selectList(prodSearch);
        System.out.println(prodList.size());
        for (Prod prod : prodList) {
            System.out.println(prod.toString());
        }
    }

    @Test
    public void selectListWithLikeTest() {
        ProdSearch prodSearch = new ProdSearch();
        prodSearch.setPagingYn(true);
        prodSearch.setStart(0);
        prodSearch.setLength(8);
        prodSearch.setSort("REG_DT");
        prodSearch.setSortOrd("ASC");
        List<Prod> prodList = clfdProdService.selectListWithLike(prodSearch, 176L);
        for (Prod prod : prodList) {
            System.out.println(prod.toString());
            System.out.println(prod.isLike());
        }
    }
}
