package main

import (
	"testing"
)

// TestFormatFlag tests the custom FormatFlag type
func TestFormatFlag(t *testing.T) {
	tests := []struct {
		name     string
		value    string
		wantErr  bool
		expected FormatFlag
	}{
		{
			name:     "valid svg",
			value:    "svg",
			wantErr:  false,
			expected: FormatSVG,
		},
		{
			name:     "valid png",
			value:    "png",
			wantErr:  false,
			expected: FormatPNG,
		},
		{
			name:     "invalid format",
			value:    "jpeg",
			wantErr:  true,
			expected: "",
		},
		{
			name:     "empty string",
			value:    "",
			wantErr:  true,
			expected: "",
		},
		{
			name:     "case sensitivity",
			value:    "SVG",
			wantErr:  true,
			expected: "",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			var f FormatFlag
			err := f.Set(tt.value)

			if (err != nil) != tt.wantErr {
				t.Errorf("FormatFlag.Set() error = %v, wantErr %v", err, tt.wantErr)
				return
			}

			if !tt.wantErr && f != tt.expected {
				t.Errorf("FormatFlag.Set() = %v, want %v", f, tt.expected)
			}
		})
	}
}

// TestFormatFlagString tests the String() method
func TestFormatFlagString(t *testing.T) {
	tests := []struct {
		name     string
		flag     FormatFlag
		expected string
	}{
		{
			name:     "svg format",
			flag:     FormatSVG,
			expected: "svg",
		},
		{
			name:     "png format",
			flag:     FormatPNG,
			expected: "png",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := tt.flag.String()
			if result != tt.expected {
				t.Errorf("FormatFlag.String() = %v, want %v", result, tt.expected)
			}
		})
	}
}

// TestFormatFlagType tests the Type() method
func TestFormatFlagType(t *testing.T) {
	var f FormatFlag
	if f.Type() != "string" {
		t.Errorf("FormatFlag.Type() = %v, want %v", f.Type(), "string")
	}
}

// TestFormatFlagConstants tests that the constants are defined correctly
func TestFormatFlagConstants(t *testing.T) {
	if FormatSVG != "svg" {
		t.Errorf("FormatSVG = %v, want %v", FormatSVG, "svg")
	}

	if FormatPNG != "png" {
		t.Errorf("FormatPNG = %v, want %v", FormatPNG, "png")
	}
}
