package net.w_horse.excelpojo.excel.cellseeker;

import java.lang.annotation.Annotation;

import net.w_horse.excelpojo.ExcelPOJOException;
import net.w_horse.excelpojo.annotation.ExcelPOJOAnnotationParser;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;


public class HorizontalRepeatsSeeker extends AbstractRepeatsSeeker {

	@Override
	public void set(Annotation annotation, ExcelPOJOAnnotationParser parser) throws ClassNotFoundException, LinkageError, ExcelPOJOException {
		parser.setCellSeeker(annotation, this);
	}

	@Override
	int getRowLimit(Sheet sheet) {
        int colSizeMax = 0;
        for (int i = 0; i < sheet.getLastRowNum(); i++) {
            Row row = sheet.getRow(i);
            if (row == null) continue;

            int colSize = row.getLastCellNum();
            if (colSize > colSizeMax) {
                colSizeMax = colSize;
            }
        }
		return colSizeMax;
	}

	@Override
	Offset getOffset(int rowIndex) {
		return new Offset(0, rowIndex);
	}

	@Override
	Offset getOffset4MappedCell(int rowIndex) {
		return new Offset(rowIndex +1, -1);
	}

	@Override
	protected Offset getRangeOffset() {
		return new Offset(-1, 0);
	}

}
