package com.avg.zaap.crashlibrary.publish.cap.http.boundary;

import java.util.Random;

/**
 * This class serves as the default multipart boundary generator.
 * <p>
 * Created by marek.osvald on 6.6.2016.
 */
public class BoundaryGenerator implements IBoundaryGenerator {

    private Random mRandom;

    /**
     * Default constructor. Used default dependency factory.
     */
    public BoundaryGenerator() {
        this(new BoundaryGeneratorFactory());
    }

    /**
     * Parametric constructor. Sets dependency factory to be used.
     *
     * @param factory dependency factory to be used
     */
    public BoundaryGenerator(IBoundaryGeneratorFactory factory) {
        mRandom = factory.getRandom();
    }

    @Override
    public String generateBoundary() {
        StringBuilder stringBuilder = new StringBuilder();

        long currentTime = System.currentTimeMillis();
        stringBuilder.append(currentTime);
        stringBuilder.append(Math.abs(mRandom.nextInt()));

        return stringBuilder.toString();
    }

}
