package handler

import (
	"testing"
	"time"

	"github.com/denisovdennis/autohero/internal/model"
)

func TestConsumeFreeBuffCharge_SubscriptionSkipsQuota(t *testing.T) {
	h := &model.Hero{SubscriptionActive: true, BuffFreeChargesRemaining: 0}
	now := time.Now()
	if err := consumeFreeBuffCharge(h, now); err != nil {
		t.Fatal(err)
	}
	if h.BuffFreeChargesRemaining != 0 {
		t.Fatalf("expected no charge mutation for subscriber, got %d", h.BuffFreeChargesRemaining)
	}
}

func TestConsumeFreeBuffCharge_Exhausted(t *testing.T) {
	end := time.Now().Add(time.Hour)
	h := &model.Hero{
		BuffFreeChargesRemaining: 0,
		BuffQuotaPeriodEnd:       &end,
	}
	if err := consumeFreeBuffCharge(h, time.Now()); err == nil {
		t.Fatal("expected error when exhausted")
	}
}
