package message

import (
	"encoding/json"
	"testing"

	messagedomain "hyapp/services/activity-service/internal/domain/message"
)

func TestConfirmIMPayloadActionsExposeAppButtonLabels(t *testing.T) {
	payloadJSON, err := confirmIMPayloadJSON("cfm_1", messagedomain.RoleInvitationConfirmEvent{
		InvitationID:   901,
		InvitationType: "host",
		InviterUserID:  1001,
		TargetUserID:   2002,
	}, "Alice has invited you to join ABC guild", 1760000000000)
	if err != nil {
		t.Fatalf("confirmIMPayloadJSON failed: %v", err)
	}
	var payload struct {
		Type    string `json:"type"`
		Actions []struct {
			Action string `json:"action"`
			Label  string `json:"label"`
			Text   string `json:"text"`
			Style  string `json:"style"`
		} `json:"actions"`
	}
	if err := json.Unmarshal([]byte(payloadJSON), &payload); err != nil {
		t.Fatalf("payload must be valid JSON: %v", err)
	}
	if payload.Type != "im_confirm" || len(payload.Actions) != 2 {
		t.Fatalf("confirm payload shape mismatch: %+v", payload)
	}
	// Flutter 现在线上按 label 渲染按钮，text 只作为旧解析兼容字段；两个字段必须一起存在。
	if payload.Actions[0].Action != "reject" || payload.Actions[0].Label != "Reject" || payload.Actions[0].Text != "Reject" || payload.Actions[0].Style != "secondary" {
		t.Fatalf("reject action mismatch: %+v", payload.Actions[0])
	}
	if payload.Actions[1].Action != "accept" || payload.Actions[1].Label != "Accept" || payload.Actions[1].Text != "Accept" || payload.Actions[1].Style != "primary" {
		t.Fatalf("accept action mismatch: %+v", payload.Actions[1])
	}
}
