package model

import "testing"

func TestRentalOrderApplyDepositHold(t *testing.T) {
	order := RentalOrder{
		DepositAmountCent: 1000,
		DepositHoldStatus: DepositHoldStatusHeld,
	}

	actualRefundCent := order.ApplyDepositHold(1500, 1000)
	if actualRefundCent != 500 {
		t.Fatalf("actual refund = %d, want 500", actualRefundCent)
	}
	if order.DepositHoldAmountCent != 1000 {
		t.Fatalf("hold amount = %d, want 1000", order.DepositHoldAmountCent)
	}
}

func TestRentalOrderApplyDepositHoldKeepsWithholdingAfterAmountRecorded(t *testing.T) {
	order := RentalOrder{
		DepositAmountCent:     1000,
		DepositHoldStatus:     DepositHoldStatusHeld,
		DepositHoldAmountCent: 1000,
	}

	actualRefundCent := order.ApplyDepositHold(1500, 1000)
	if actualRefundCent != 500 {
		t.Fatalf("actual refund = %d, want 500", actualRefundCent)
	}
	if order.DepositHoldAmountCent != 1000 {
		t.Fatalf("hold amount = %d, want 1000", order.DepositHoldAmountCent)
	}
}

func TestRentalOrderApplyDepositHoldSkipsWhenNotHeld(t *testing.T) {
	order := RentalOrder{
		DepositAmountCent: 1000,
		DepositHoldStatus: DepositHoldStatusNone,
	}

	actualRefundCent := order.ApplyDepositHold(1500, 1000)
	if actualRefundCent != 1500 {
		t.Fatalf("actual refund = %d, want 1500", actualRefundCent)
	}
	if order.DepositHoldAmountCent != 0 {
		t.Fatalf("hold amount = %d, want 0", order.DepositHoldAmountCent)
	}
}
