package usecase

import (
	"context"
	"testing"

	"haixun-backend/internal/model/job/domain/entity"
	domusecase "haixun-backend/internal/model/job/domain/usecase"
)

func TestUpsertTemplate_SetsDefaults(t *testing.T) {
	ctx := context.Background()
	repo := &memoryTemplateRepo{}
	uc := NewUseCase(repo, newMemoryRunRepo(nil), &memoryScheduleRepo{}, &memoryEventRepo{}, newMemoryQueueRepo())

	template, err := uc.UpsertTemplate(ctx, domusecase.UpsertTemplateRequest{
		Type:    "custom_job",
		Name:    "Custom Job",
		Enabled: true,
		Steps: []entity.TemplateStep{{
			ID:         "step1",
			Name:       "Step 1",
			WorkerType: "go",
		}},
	})
	if err != nil {
		t.Fatalf("UpsertTemplate() error = %v", err)
	}
	if template.ConcurrencyPolicy != "reject_same_scope" {
		t.Fatalf("ConcurrencyPolicy = %q", template.ConcurrencyPolicy)
	}
	if template.CancelPolicy.GraceSeconds != 30 {
		t.Fatalf("GraceSeconds = %d, want 30", template.CancelPolicy.GraceSeconds)
	}
}
