package com.example;
import com.groupdocs.cloud.watermark.client.*;
import com.groupdocs.cloud.watermark.model.*;
import com.groupdocs.cloud.watermark.model.requests.AddRequest;
import com.groupdocs.cloud.watermark.api.WatermarkApi;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
        
		String ClientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
		String ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
		String myStorage = "test";
		// Create an object of the Configuration class and initialize it with Client ID and Client Secret.
		Configuration configuration = new Configuration(ClientId, ClientSecret);			
		// Initialize an instance of the WatermarkApi class with the instance of the configuration.
		WatermarkApi apiInstance = new WatermarkApi(configuration);
		// Create an object of the FileInfo class.
		FileInfo fileInfo = new FileInfo();
		// Set PNG file path by calling the setFilePath method.
		fileInfo.setFilePath("sample.png");
		fileInfo.setStorageName(myStorage);
		// Define Watermark options by creating an instance of the WatermarkOptions class. 
		WatermarkOptions options = new WatermarkOptions();
		// Invoke the setFileInfo method to define the source file. 
		options.setFileInfo(fileInfo);
		// Define text watermark options such as watermark text, font family, font size, etc.
		TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
		textWatermarkOptions.setText("GroupDocs watermark");
		textWatermarkOptions.setFontFamilyName("Arial");
		textWatermarkOptions.setFontSize(12d);
		textWatermarkOptions.setTextAlignment("Center");

		// Set Watermark text color by creating an object of the Color class and invoking the setForegroundColor method.
		Color color = new Color();
		color.setName("White");
		textWatermarkOptions.setForegroundColor(color);
		// Define watermark details by calling the setTextWatermarkOptions method of the WatermarkDetails class.
		WatermarkDetails watermarkDetails = new WatermarkDetails();
		watermarkDetails.setTextWatermarkOptions(textWatermarkOptions);

		// Create an object of the Position class and set watermark position.
		Position position = new Position();
		position.setX(180.0);
		position.setY(450.0);
		watermarkDetails.setPosition(position);

		// set watermark details
		List<WatermarkDetails> watermarkDetailsList = new ArrayList<WatermarkDetails>();
		watermarkDetailsList.add(watermarkDetails);
		options.setWatermarkDetails(watermarkDetailsList);

		// Create a request to add watermark by creating an instance of the AddRequest class.
		AddRequest request = new AddRequest(options);
		WatermarkResult response;
		try {
			// Invoke the add method of the WatermarkApi class to add watermark to PNG.
			response = apiInstance.add(request);
			System.out.println("Resultant file path: " + response.getPath());
		} catch (ApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}