package com.bonus.canteen.core.notice.print.v2.api;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.device.manage.dto.DeviceDTO;
import com.bonus.canteen.core.notice.print.v2.business.NoticePrinterBusiness;
import com.bonus.canteen.core.notice.print.v2.factory.NoticePrinterFactory;
import com.bonus.canteen.core.notice.print.v2.service.NoticePrintTemplateService;
import com.bonus.canteen.core.notice.print.v2.vo.NoticePrintTemplateVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DevicePrintExtSettingApi {
   private static final Logger log = LoggerFactory.getLogger(DevicePrintExtSettingApi.class);
   @Autowired
   @Lazy
   private NoticePrintTemplateService noticePrintTemplateService;
   @Autowired
   @Lazy
   private NoticePrinterFactory noticePrinterFactory;

   public Map<String, List<NoticePrintTemplateVO>> findPrintTemplateListByPrintModel(String printModel) {
      return this.noticePrintTemplateService.findPrintTemplateListByPrintModel(printModel);
   }

   public void setPrinterSize(DeviceDTO deviceDTO) {
      NoticePrinterBusiness noticePrinterBusiness = this.noticePrinterFactory
              .getNoticePrinterBusiness(deviceDTO.getDeviceModel());
      if (ObjectUtil.isNull(noticePrinterBusiness)) {
         log.info("不支持该类打印机");
      } else {
         noticePrinterBusiness.setPrinterSize(deviceDTO);
      }
   }
}
