package flattens

import (
	"context"

	"github.com/google/uuid"
	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/models"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/kvmvm/utilities"
)

func DataSourceComputeGetLog(ctx context.Context, state *models.GetLogModel, c *client.Client) diag.Diagnostics {
	tflog.Info(ctx, "Start FlattenDataSourceComputeGetLog")

	diags := diag.Diagnostics{}

	log, err := utilities.ComputeGetLogCheckPresence(ctx, state, c)
	if err != nil {
		diags.AddError("Error get compute log", err.Error())
		return diags
	}

	id := uuid.New()

	*state = models.GetLogModel{
		ComputeID: state.ComputeID,
		Path:      state.Path,
		Timeouts:  state.Timeouts,
		Id:        types.StringValue(id.String()),
		Log:       types.StringValue(log),
	}

	tflog.Info(ctx, "End FlattenDataSourceComputeGetLog")
	return nil
}
