package cn.com.qmth.stmms.common.utils;

import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * 答题卡扫描大图URL构造工具类
 * 
 * @author LS
 * 
 */
public class PictureUrlBuilder {

    private static final String SHEET_URL_TEMPLATE = "/{0}-{1}/{2}/{3}-{4}.{5}";

    private static final String SLICE_URL_TEMPLATE = "/{0}-{1}/{2}/{3}-{4}.{5}";

    private static final String ANSWER_URL_TEMPLATE = "/{0}/answer/{1}.{2}";

    private static final String PAPER_URL_TEMPLATE = "/{0}/paper/{1}.{2}";

    private static final String PACKAGE_URL_TEMPLATE = "/{0}/{1}/{2}.{3}";

    private static final String DEFAULT_SUFFIX = "jpg";

    private static final String DOCUMENT_SUFFIX = "pdf";

    public static List<String> getSheetUrls(int examId, int campusId, String subjectCode, String examNumber, int count) {
        List<String> list = new LinkedList<String>();
        if (StringUtils.isNotEmpty(subjectCode) && count > 0) {
            for (int i = 1; i <= count; i++) {
                list.add(MessageFormat.format(SHEET_URL_TEMPLATE, String.valueOf(examId), String.valueOf(campusId),
                        subjectCode, examNumber, String.valueOf(i), DEFAULT_SUFFIX));
            }
        }
        return list;
    }

    public static List<String> getSliceUrls(int examId, int campusId, String subjectCode, String examNumber, int start,
            int count) {
        List<String> list = new LinkedList<String>();
        if (StringUtils.isNotEmpty(subjectCode) && count > 0) {
            for (int i = start; i <= count; i++) {
                list.add(MessageFormat.format(SLICE_URL_TEMPLATE, String.valueOf(examId), String.valueOf(campusId),
                        subjectCode, examNumber, String.valueOf(i), DEFAULT_SUFFIX));
            }
        }
        return list;
    }

    public static String getAnswerUrl(int examId, String subjectCode) {
        return MessageFormat.format(ANSWER_URL_TEMPLATE, String.valueOf(examId), subjectCode, DOCUMENT_SUFFIX);
    }

    public static String getPaperUrl(int examId, String subjectCode) {
        return MessageFormat.format(PAPER_URL_TEMPLATE, String.valueOf(examId), subjectCode, DOCUMENT_SUFFIX);
    }

    public static List<String> getPackageUrls(int examId, String packageCode, int count) {
        List<String> list = new LinkedList<String>();
        if (StringUtils.isNotEmpty(packageCode) && count > 0) {
            for (int i = 1; i <= count; i++) {
                list.add(MessageFormat.format(PACKAGE_URL_TEMPLATE, String.valueOf(examId), packageCode,
                        String.valueOf(i), DEFAULT_SUFFIX));
            }
        }
        return list;
    }
}
