package converter

import (
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/api/v1"
	"github.com/AlchemyTelcoSolutions/callisto-so-bff/internal/domain/model"
	"reflect"
	"testing"
)

func TestToHTTPResponse(t *testing.T) {
	val := 1
	errS := map[string]interface{}{
		"message": "internal server error",
	}
	errModel := model.Response[int]{
		Result:  nil,
		Success: false,
		Error:   &errS,
	}

	type args[T any] struct {
		m *model.Response[T]
	}
	type testCase[T any] struct {
		name string
		args args[T]
		want api.Response
	}
	tests := []testCase[int]{
		{
			name: "Success",
			args: args[int]{
				m: &model.Response[int]{
					Result:  &val,
					Success: true,
				},
			},
			want: api.Response{
				Result:  &val,
				Success: true,
			},
		},
		{
			name: "SuccessConvert_WithErrorFieldExist",
			args: args[int]{
				m: &errModel,
			},
			want: api.Response{
				Result:  errModel.Result,
				Success: false,
				Error:   &errS,
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := ToHTTPResponse(tt.args.m); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("ToHTTPResponse() = %v, want %v", got, tt.want)
			}
		})
	}
}
