package com.style24.batch.biz.job.shoplinker;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.core.biz.service.TscShoplinkerService;
import com.style24.persistence.domain.ShoplinkerInvoice;

import lombok.extern.slf4j.Slf4j;


/**
 * 샵링커 송장전송
 *
 * @author jmh
 * @since 2021.06.22
*/
@Component
@Slf4j
public class TsbShoplinkerInvoiceJob extends TsbAbstractJob<Collection<ShoplinkerInvoice>, Collection<ShoplinkerInvoice>, String>{

	@Autowired
	private TscShoplinkerService shoplinkerService;

	@Autowired
	private Environment env;


	@Override
	public Collection<ShoplinkerInvoice> read() throws Exception {
		return shoplinkerService.getShoplinkerInvoiceOrdDtlSendList();
	}

	@Override
	public Collection<ShoplinkerInvoice> process(Collection<ShoplinkerInvoice> list) throws Exception {
		return list;
	}

	@Override
	public String write(Collection<ShoplinkerInvoice> list) throws Exception {

		ShoplinkerInvoice shoplinkerInvoice = new ShoplinkerInvoice();
		shoplinkerInvoice.setXmlPath(env.getProperty("shoplinker.xml.path")+"/invoice");
		shoplinkerInvoice.setDomainUrl(env.getProperty("shoplinker.xml.view")+"/invoice");
		shoplinkerInvoice.setCustomerId(env.getProperty("shoplinker.customer_id"));

		shoplinkerService.createShoplinkerInvoiceXml(shoplinkerInvoice, list);
		return "OK";
	}

	@Override
	public void notify(String result) throws Exception {
		// Do nothing
	}
}
