package com.style24.admin.biz.service;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.excel.GagaExcelUtil;
import com.gagaframework.excel.env.GagaExcelConstants;
import com.gagaframework.web.parameter.GagaMap;

import com.style24.admin.biz.dao.TsaPosDao;
import com.style24.persistence.domain.Pos;

/**
 * 매장POS Service
 * 
 * @author moon
 * @since 2020. 11. 13
 */
@Service
@Slf4j
public class TsaPosService {

	@Autowired
	private TsaPosDao posDao;

	/**
	 * 매장로그인 정보 조회
	 * 
	 * @param pos - 매장정보
	 * @return Pos
	 * @author moon
	 * @since 2020. 11. 13
	 */
	public Pos getStoreLoginInfo(Pos pos) {
		return posDao.getStoreLoginInfo(pos);
	}

	/**
	 * 출고대기/출고목록
	 * 
	 * @param pos - 매장정보
	 * @return Collection<Pos>
	 * @author moon
	 * @since 2020. 11. 13
	 */
	public Collection<Pos> getPosDeliveryList(Pos pos) {
		return posDao.getPosDeliveryList(pos);
	}

	/**
	 * 정산내역
	 * 
	 * @param pos - 매장정보
	 * @return Collection<Pos>
	 * @author moon
	 * @since 2020. 11. 13
	 */
	public Collection<Pos> getPosUsacList(Pos pos) {
		return posDao.getPosUsacList(pos);
	}

	/**
	 * CNPlus 엑셀다운로드
	 * 
	 * @param pos - 매장정보
	 * @return Pos
	 * @author moon
	 * @since 2020. 11. 13
	 */
	public void getOrderExcelList(Pos pos, String excelFilenameWithPath) {

		// 헤더 title 설정

		String[] listTitles = {"예약구분", "집하예정일", "받는분성명"  //3
			, "받는분전화번호", "받는분기타연락처", "받는분우편번호" //3
			, "받는분주소(전체, 분할)", "운송장번호", "고객주문번호" //3
			, "품목명", "박스수량", "박스타입", "기본운임"  //4
			, "배송메세지1", "배송메세지2", "품목명"};  //3

		// DB 처리 시 사용되는 파라미터명(셀명) 설정
		String[] cellNames = {"RSRVT_GB", "SCHDL_CLDT", "RECIP_NM"  //3
			, "RECIP_PHNNO", "RECIP_TELNO", "RECIP_POST_NO" //3
			, "RECIP_ADDR", "INVOICE_NO", "ORD_NO"  //3
			, "GOODS_NM", "BOX_QTY", "BOX_TYPE", "FEE" //4
			, "DELV_MEMO", "DELV_MEMO2", "GOODS_CD"}; //3

		String[] cellTypes = {GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name(),
			GagaExcelConstants.CellType.CHAR_LEFT.name(), GagaExcelConstants.CellType.CHAR_LEFT.name()
		};
		Collection<GagaMap> dataList = posDao.getOrderExcelList(pos); // map형식으로 조회
		try {
			GagaExcelUtil.createExcel(excelFilenameWithPath, dataList, cellNames, cellTypes);

		} catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}
	
	public GagaMap getChkShopRt(Pos tsaPos) {
		GagaMap result = new GagaMap();
		int cnt = posDao.getShopRtCheck(tsaPos);
		if(cnt > 0) {
			result.set("chk", "Y");
		} else {
			result.set("chk", "N");
		}
		return result;
	}

}
