package radar

import (
	"context"
	"encoding/json"
	"errors"
	"net/http"
	"net/http/httptest"
	"testing"

	"apps/backend/internal/domain"
	radarDomain "apps/backend/internal/module/radar/domain"
	"apps/backend/internal/response"
)

// notReady envelope 契約：若日後有殘留未實作 route 仍須回 501／501010，不可 102000 空成功。
func TestNotReadyEnvelope(t *testing.T) {
	err := notReady("example.capability")
	if !errors.Is(err, radarDomain.ErrNotReady) {
		t.Fatalf("expected ErrNotReady, got %v", err)
	}
	rec := httptest.NewRecorder()
	response.Write(context.Background(), rec, nil, err)
	if rec.Code != http.StatusNotImplemented {
		t.Fatalf("expected HTTP 501, got %d", rec.Code)
	}
	var env response.Envelope
	if decErr := json.NewDecoder(rec.Body).Decode(&env); decErr != nil {
		t.Fatalf("decode envelope: %v", decErr)
	}
	if env.Code == domain.SuccessCode {
		t.Fatal("not-ready must not use success code")
	}
}
