package dev.fyloz.trial.colorrecipesexplorer.service.files;

import dev.fyloz.trial.colorrecipesexplorer.utils.PdfBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class TouchUpKitService {

    private static final String TOUCH_UP_FR = "KIT DE RETOUCHE";
    private static final String TOUCH_UP_EN = "TOUCH UP KIT";
    public static final int FONT_SIZE = 42;

    private ResourceLoader resourceLoader;

    @Autowired
    public TouchUpKitService(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    /**
     * Génère un PDF de kit de retouche pour une job.
     *
     * @param jobNumber La job
     * @return Le PDF de kit de retouche pour la job
     */
    public byte[] generatePdfForJobNumber(String jobNumber) {
        try {
            return new PdfBuilder(resourceLoader, true, FONT_SIZE)
                    .addLine(TOUCH_UP_FR, true, 0)
                    .addLine(TOUCH_UP_EN, true, 0)
                    .addLine(jobNumber, false, 10)
                    .build();
        } catch (IOException ex) {
            throw new RuntimeException(String.format("Impossible de générer un PDF de kit de retouche pour la job '%s': %s", jobNumber, ex.getMessage()));
        }
    }

}
