package bbs

import (
	"sync"
	"testing"

	"github.com/Ptt-official-app/go-pttbbs/types"
)

func TestWriteFavorites(t *testing.T) {
	setupTest()
	defer teardownTest()

	content0 := []byte{
		0x23, 0x0d, 0x03, 0x00, 0x02, 0x01, 0x01, 0x01,
		0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x02,
		0x01, 0x01, 0xb7, 0x73, 0xaa, 0xba, 0xa5, 0xd8,
		0xbf, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x03, 0x01, 0x02, 0x01, 0x01,
		0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x08, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
		0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
	}

	type args struct {
		uuserID UUserID
		content []byte
	}
	tests := []struct {
		name      string
		args      args
		wantMtime types.Time4
		wantErr   bool
	}{
		// TODO: Add test cases.
		{
			args: args{uuserID: "SYSOP", content: content0},
		},
	}

	var wg sync.WaitGroup
	for _, tt := range tests {
		wg.Add(1)
		t.Run(tt.name, func(t *testing.T) {
			defer wg.Done()

			now := types.NowTS()
			gotMtime, err := WriteFavorites(tt.args.uuserID, tt.args.content)
			if (err != nil) != tt.wantErr {
				t.Errorf("WriteFavorites() error = %v, wantErr %v", err, tt.wantErr)
				return
			}

			if gotMtime-now > 2 {
				t.Errorf("mTime: %v, now: %v", gotMtime, now)
			}
		})
		wg.Wait()
	}
}
