package com.style24.scm.biz.service;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gagaframework.excel.env.GagaExcelConstants;
import com.gagaframework.excel.xssf.GagaExcelResultHandler;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.Order;
import com.style24.scm.biz.dao.TssOrderDao;
import com.style24.scm.support.security.session.TssSession;

import lombok.extern.slf4j.Slf4j;

import com.style24.scm.support.util.TsitUtil;

/**
 * 주문 Service
 *
 * @author gagamel
 * @since 2020. 10. 19
 */
@Service
@Slf4j
public class TssOrderService {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TssOrderDao orderDao;
	
	/**
	 * 주문목록
	 * @param Order
	 * @return
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderList(Order order) {
		return orderDao.getOrderList(order);
	}
	
	/**
	 * 주문리스트 합계
	 *
	 * @param order
	 * @return Order - 합계정보
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Order getOrderListSumInfo(Order order) {
		// multi row 검색관련 처리
		if (StringUtils.isNotBlank(order.getCondition())) {
			TsitUtil tsitUtil = new TsitUtil();
			String searchCondition = tsitUtil.replaceMultiSelectParamsArr(order.getCondition());
			order.setConditions(searchCondition.split(","));
		}

		// 외부몰권한일 때 외부몰벤더ID 설정
		//if (TsaSession.getInfo().getRoleCd().startsWith("C")) {
			//order.setMallGb(TsaConstants.MallGb.EXTMALL.value());
			//order.setVendorId(TsaSession.getInfo().getVendorId());
		//}
		
		return orderDao.getOrderListSumInfo(order);
	}
	
	/**
	 * 주문상세 정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderInfoList(Order order) {
		return orderDao.getOrderInfoList(order);
	}
	
	/**
	 * 주문상세 목록
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderDetailList(Order order) {
		return orderDao.getOrderDetailList(order);
	}
	
	/**
	 * 배송정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getDeliveryAddrList(Order order) {
		return orderDao.getDeliveryAddrList(order);
	}
	
	/**
	 * 주문상세 단품 목록
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderDetailItemList(Order order) {
		return orderDao.getOrderDetailItemList(order);
	}
	
	/**
	 * 결제내역 > 결제 기본정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderPaymentBasicInfoList(Order order) {
		return orderDao.getOrderPaymentBasicInfoList(order);
	}
	
	/**
	 * 배송비 정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getDeliveryFeeList(Order order) {
		return orderDao.getDeliveryFeeList(order);
	}
	
	/**
	 * 취소/반품/교환 요청 정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderChangeList(Order order) {
		return orderDao.getOrderChangeList(order);
	}
	
	/**
	 * 환불정보
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> orderRefundInfo(Order order) {
		return orderDao.orderRefundInfo(order);
	}
	
	/**
	 * 상담내역
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> orderCounselInfo(Order order) {
		return orderDao.orderCounselInfo(order);
	}
	
	/**
	 * 변경내역 > 주문요청 관리자 메모
	 *
	 * @param order - 주문 정보
	 * @return Collection<Order>
	 * @author jsh77b
	 * @since 2020. 11. 18
	 */
	public Collection<Order> getOrderTsainMemoList(Order order) {
		order.setDelYn("N");
		return orderDao.getOrderTsainMemoList(order);
	}
}
