package imagery_test

import "seekia/internal/imageFiles"
import "seekia/internal/encoding"
//import "seekia/internal/helpers"
import "seekia/internal/imagery"

import "image"
import "testing"
//import "os"

func TestReadWriteImages(t *testing.T){

	ultrawideImageFileBytes := imageFiles.PNG_Ultrawide

	ultrawideGoImage, err := imagery.ConvertPNGImageFileBytesToGolangImage(ultrawideImageFileBytes)
	if (err != nil) {
		t.Fatal("Failed to read JPG image file: " + err.Error())
	}

	pumpkinFileBytes := imageFiles.PNG_Pumpkin

	pumpkinGoImage, err := imagery.ConvertPNGImageFileBytesToGolangImage(pumpkinFileBytes)
	if (err != nil) {
		t.Fatal("Failed to read png image file: " + err.Error())
	}

	goImagesList := []image.Image{ultrawideGoImage, pumpkinGoImage}

	for _, imageObject := range goImagesList{

		standardImageBase64, err := imagery.ConvertImageObjectToStandardJPEGBase64String(imageObject)
		if (err != nil) {
			t.Fatal("Failed to crop and compress standard image: " + err.Error())
		}

		standardImageBytes, err := encoding.DecodeBase64StringToBytes(standardImageBase64)	
		if (err != nil) {
			t.Fatal("Failed to decode standard image base64 string: " + err.Error())
		}

		isValid, err := imagery.VerifyStandardImageBytes(standardImageBytes)
		if (err != nil) {
			t.Fatal("Failed to VerifyStandardImageBytes: " + err.Error())
		}
		if (isValid == false){
			t.Fatal("Produced standard image is not valid.")
		}

		/*

		fileNameIndex := helpers.ConvertIntToString(index+1)

		fileMode := os.FileMode(0755)

		fileName := "Image" + fileNameIndex + ".jpg"

		err = os.WriteFile(fileName, standardImageBytes, fileMode)
		if (err != nil)  {
			t.Fatal("Failed to write image: " + err.Error())
		}

		*/
	}

	isValid, err := imagery.VerifyStandardImageBytes(ultrawideImageFileBytes)
	if (err != nil) {
		t.Fatal("Failed to VerifyStandardImageBytes: " + err.Error())
	}
	if (isValid == true){
		t.Fatal("VerifyStandardImageBytes allowing ultrawide image.")
	}
}


