package com.bankaudit.template.rest.service;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("FileUploadWriteTemplateService")
@Transactional("transactionManager")
public class FileUploadWriteTemplateImpl implements FileUploadWriteTemplateService {

	@Override
	public HSSFWorkbook writeTemplate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Object[]> getUploadType() {
		// TODO Auto-generated method stub
		return null;
	}/*

	
	@Autowired(required=true)
	FileUploadDao fileUploadDao;
	//HSSFWorkbook hwb;
	
	static HSSFDataFormat format = null;
	
	public HSSFWorkbook writeTemplate(String tableName) throws Exception {
		HSSFWorkbook hwb =null;
		//Variable declaration
		HSSFRow rowHead = null;
		HSSFCell cell =null;	     
		
		int cellIndex=0;
		int rowIndex=0;
		
		//Sheet Creation
		HSSFSheet sheet = null;
		
		//Cell Styles
		HSSFCellStyle headerStyle = null;
		HSSFCellStyle style = null;
		
		try 
		{
           
			//WorkBook Creation
			hwb=new HSSFWorkbook();

			format = hwb.createDataFormat();
			style = hwb.createCellStyle();
			style.setDataFormat(format.getFormat("@"));

			//Sheet Creation
			sheet = hwb.createSheet(tableName.trim());

			//Freeze Pane
			sheet.createFreezePane( 0, 2);

			//Cell Styles
			headerStyle = setHeaderStyle(hwb);

			@SuppressWarnings("unchecked")
			List<FileUploadTemplateV> futList =	fileUploadDao.createTemplate(tableName);
			
			//Row 1
			rowHead=sheet.createRow((short)rowIndex++);
			rowHead.setHeight((short) 400);
			int i=1;
			for (FileUploadTemplateV fileUploadTemplateV : futList) {
				sheet.setColumnWidth(i-1, fileUploadTemplateV.getColumnName().length() * 1024);
				cell = rowHead.createCell(cellIndex++);
				sheet.setDefaultColumnStyle((short) i, style);
				cell.setCellStyle(headerStyle);
				cell.setCellValue(new HSSFRichTextString(fileUploadTemplateV.getColumnName()));
			}
			
			//auto Set Column widths
			autoSizeColumns(hwb);
			
		}catch (Exception e) {
            e.printStackTrace();
		}
		return hwb;
	}
	

	
	public static HSSFCellStyle setHeaderStyle(HSSFWorkbook wb)
	{
		HSSFCellStyle style = wb.createCellStyle();
		
		HSSFFont  font= wb.createFont();
		font.setFontHeightInPoints((short) 12);
		font.setFontName(HSSFFont.FONT_ARIAL);
		font.setBoldweight((short) HSSFFont.BOLDWEIGHT_BOLD);
		font.setColor((short) HSSFColor.WHITE.index);
		style.setFont(font);
		
		style.setDataFormat(format.getFormat("@"));
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
		style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
		style.setBorderRight(HSSFCellStyle.BORDER_THIN);
		style.setBorderTop(HSSFCellStyle.BORDER_THIN);
		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style.setFillForegroundColor(new HSSFColor.DARK_BLUE().getIndex());// GREY_50_PERCENT().getIndex());
		return style;
	}
	
	
	public static HSSFCellStyle getCellStyleForNormalCellsWithSuffixZero(HSSFWorkbook workBook)
	{
		HSSFCellStyle textStyle = workBook.createCellStyle();
		HSSFFont font = workBook.createFont();
		textStyle.setFont(font);
		textStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		textStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
		textStyle.setLocked(false);
		return (textStyle);
		
	}
	
	public static String getSuffixZeroumberStyle(String value){
		String temp="";
        try 
        {
        	if(value!=null){

    			Integer.parseInt(value);
    	         if(value!=null)
    	         {                                    	  
    	             for(int i=0;i<value.length();i++)
    	             {
    	           	  temp+="0";
    	             }
    	         }
    		
        	}
        	
        }catch (NumberFormatException e){
			e.printStackTrace();
		}
		return temp;
	 }
	
	
	
	public static void setNumericConstraints(HSSFSheet spreadSheet, int startRow,int endRow, int startCell, int endCell) {
		CellRangeAddressList addressList = new CellRangeAddressList(startRow,endRow, 0, 0);
		DVConstraint dvConstraint = DVConstraint.createNumericConstraint(DVConstraint.ValidationType.INTEGER,DVConstraint.OperatorType.BETWEEN, "0","9999999999999999999999999");
		HSSFDataValidation dataValidation = new HSSFDataValidation(addressList,	dvConstraint);
		dataValidation.setSuppressDropDownArrow(true);
		spreadSheet.addValidationData(dataValidation);
	}
	
	public void autoSizeColumns(HSSFWorkbook workbook) {
	    int numberOfSheets = workbook.getNumberOfSheets();
	    for (int i = 0; i < numberOfSheets; i++) {
	    	HSSFSheet sheet = workbook.getSheetAt(i);
	        if (sheet.getPhysicalNumberOfRows() > 0) {
	            HSSFRow row = sheet.getRow(0);
	            Iterator<HSSFCell> cellIterator = row.cellIterator()null;
	            while (cellIterator.hasNext()) {
	            	HSSFCell cell = cellIterator.next();
	                int columnIndex = cell.getColumnIndex();
	                sheet.autoSizeColumn((short) columnIndex);
	            }
	        }
	    }
	}

	@Override
	public List<Object[]> getUploadType() {
		// TODO Auto-generated method stub
		return fileUploadDao.getUploadType();
	}
*/}
