package domain_test

import (
	"testing"

	"source.toby3d.me/toby3d/home/internal/common"
	"source.toby3d.me/toby3d/home/internal/domain"
)

func TestLanguage_Lang(t *testing.T) {
	t.Parallel()

	for name, tc := range map[string]struct {
		input  string
		expect string
	}{
		"2letter":  {"en", "en"},
		"3letter":  {"eng", "en"},
		"region":   {"en-US", "en"},
		common.Und: {"", ""},
	} {
		name, tc := name, tc

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if actual := domain.NewLanguage(tc.input).Lang(); actual != tc.expect {
				t.Errorf("Lang() = %s, want %s", actual, tc.expect)
			}
		})
	}
}

func TestLanguage_Code(t *testing.T) {
	t.Parallel()

	for name, tc := range map[string]struct {
		input  string
		expect string
	}{
		"2letter":  {"en", "en"},
		"3letter":  {"eng", "en"},
		"region":   {"en-US", "en-US"},
		common.Und: {"", ""},
	} {
		name, tc := name, tc

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if actual := domain.NewLanguage(tc.input).Code(); actual != tc.expect {
				t.Errorf("Code() = %s, want %s", actual, tc.expect)
			}
		})
	}
}

func TestLanguage_Dir(t *testing.T) {
	t.Parallel()

	for name, tc := range map[string]struct {
		input  string
		expect domain.Direction
	}{
		"2letter":  {"en", domain.DirectionLeftToRight},
		"rtl":      {"ur", domain.DirectionRightToLeft},
		"3letter":  {"eng", domain.DirectionLeftToRight},
		"region":   {"en-US", domain.DirectionLeftToRight},
		common.Und: {"", domain.DirectionUnd},
	} {
		name, tc := name, tc

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if actual := domain.NewLanguage(tc.input).Dir(); actual != tc.expect {
				t.Errorf("Dir() = %s, want %s", actual, tc.expect)
			}
		})
	}
}

func TestLanguage_Name(t *testing.T) {
	t.Parallel()

	for name, tc := range map[string]struct {
		input  string
		expect string
	}{
		"localized": {"ru", "русский"},
		"2letter":   {"en", "english"},
		"3letter":   {"eng", "english"},
		"region":    {"en-US", "american english"},
		common.Und:  {"", ""},
	} {
		name, tc := name, tc

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if actual := domain.NewLanguage(tc.input).Name(); actual != tc.expect {
				t.Errorf("Name() = %s, want %s", actual, tc.expect)
			}
		})
	}
}
