package gametimer

import (
	"fmt"
	"testing"
	"time"

	"gogs.daxia.dev/huanan/pkg.daxia.dev/time_utils"
)

func TestGetIssueByTime(t *testing.T) {
	//timeNow := time_utils.TimeNowInCN()

	gameTimer := &GameTimer{
		baseTime:     time.Date(2000, 1, 1, 0, 0, 0, 0, time_utils.GetCNZone()),
		baseName:     "baase_test1",
		totalSecond:  90,
		stopSecond:   70,
		currentEvent: "0000",
	}

	issueStr := gameTimer.GetIssueStrByTime(time.Date(2001, 1, 1, 0, 0, 0, 0, time_utils.GetCNZone()))
	fmt.Println("issue:", issueStr)
}

func TestGameTimer_GetIssueByTime(t *testing.T) {
	type fields struct {
		baseTime     time.Time
		baseName     string
		totalSecond  int
		stopSecond   int
		currentEvent string
	}
	type args struct {
		timeIssue time.Time
	}

	timeNow := time_utils.TimeNowInCN()
	timeIssue1 := time_utils.GetZeroTime(timeNow)
	timeIssue2 := timeIssue1.Add(90 * time.Second)
	//timeIssue = timeZero.Add(time.Hour * 24)

	tests := []struct {
		name   string
		fields fields
		args   args
		want   int64
	}{
		{
			name: "",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow),
				baseName:     "baase_test1",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				timeIssue: timeIssue1,
			},
			want: 1,
		},
		{
			name: "",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				timeIssue: timeIssue2,
			},
			want: 2,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			p := &GameTimer{
				baseTime:     tt.fields.baseTime,
				baseName:     tt.fields.baseName,
				totalSecond:  tt.fields.totalSecond,
				stopSecond:   tt.fields.stopSecond,
				currentEvent: tt.fields.currentEvent,
			}
			if got := p.GetIssueByTime(tt.args.timeIssue); got != tt.want {
				t.Errorf("GameTimer.GetIssueByTime() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestGameTimer_GetIssueStr(t *testing.T) {
	type fields struct {
		baseTime     time.Time
		baseName     string
		totalSecond  int
		stopSecond   int
		currentEvent string
	}
	type args struct {
		issue int64
	}

	timeNow := time_utils.TimeNowInCN()

	tests := []struct {
		name   string
		fields fields
		args   args
		want   string
	}{
		{
			name: "",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				issue: 1,
			},
			want: time_utils.GetFormatTime(timeNow) + " 001",
		},
		{
			name: "",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow).Add(90 * time.Second),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				issue: 1,
			},
			want: time_utils.GetFormatTime(timeNow) + " 002",
		},
		{
			name: "",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow).Add(24 * time.Hour),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				issue: 1,
			},
			want: time_utils.GetFormatTime(timeNow.Add(24*time.Hour)) + " 001",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			p := &GameTimer{
				baseTime:     tt.fields.baseTime,
				baseName:     tt.fields.baseName,
				totalSecond:  tt.fields.totalSecond,
				stopSecond:   tt.fields.stopSecond,
				currentEvent: tt.fields.currentEvent,
			}
			if got := p.GetIssueStr(tt.args.issue); got != tt.want {
				t.Errorf("GameTimer.GetIssueStr() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestGameTimer_GetIssueFromStr(t *testing.T) {
	type fields struct {
		baseTime     time.Time
		baseName     string
		totalSecond  int
		stopSecond   int
		currentEvent string
	}
	type args struct {
		issueStr string
	}

	timeNow := time_utils.TimeNowInCN()
	//timeStart2000 := time.Date(2000, 1, 1, 0, 0, 0, 0, time_utils.GetCNZone())

	tests := []struct {
		name    string
		fields  fields
		args    args
		want    int64
		wantErr bool
	}{
		{
			name: "test1",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				issueStr: time_utils.GetFormatTime(timeNow) + " 001",
			},
			want:    1,
			wantErr: false,
		},
		{
			name: "test2",
			fields: fields{
				baseTime:     time_utils.GetZeroTime(timeNow),
				baseName:     "baase_test2",
				totalSecond:  90,
				stopSecond:   60,
				currentEvent: "0000",
			},
			args: args{
				issueStr: time_utils.GetFormatTime(timeNow) + " 002",
			},
			want:    2,
			wantErr: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			p := &GameTimer{
				baseTime:     tt.fields.baseTime,
				baseName:     tt.fields.baseName,
				totalSecond:  tt.fields.totalSecond,
				stopSecond:   tt.fields.stopSecond,
				currentEvent: tt.fields.currentEvent,
			}
			got, err := p.GetIssueFromStr(tt.args.issueStr)
			if (err != nil) != tt.wantErr {
				t.Errorf("GameTimer.GetIssueFromStr() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got != tt.want {
				t.Errorf("GameTimer.GetIssueFromStr() = %v, want %v", got, tt.want)
			}
		})
	}
}
