package com.ruoyi.app.flashdelivery.service;

import org.junit.jupiter.api.Test;

import static com.ruoyi.system.domain.flash.FlashDeliveryStatus.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FlashDeliveryStateMachineTest {

    @Test
    void acceptsOnlyTheDeliveryLifecycleTransitions() {
        assertTrue(FlashDeliveryStateMachine.canTransition(WAITING_ACCEPTANCE, ACCEPTED));
        assertTrue(FlashDeliveryStateMachine.canTransition(ACCEPTED, PICKED_UP));
        assertTrue(FlashDeliveryStateMachine.canTransition(PICKED_UP, DELIVERED));
        assertTrue(FlashDeliveryStateMachine.canTransition(DELIVERED, COMPLETED));
        assertFalse(FlashDeliveryStateMachine.canTransition(ACCEPTED, DELIVERED));
        assertFalse(FlashDeliveryStateMachine.canTransition(COMPLETED, CANCELLED));
        assertFalse(FlashDeliveryStateMachine.canTransition(CANCELLED, WAITING_ACCEPTANCE));
    }

    @Test
    void userAndAdminCancellationRulesAreDifferent() {
        assertTrue(FlashDeliveryStateMachine.canUserCancel(WAITING_ACCEPTANCE));
        assertTrue(FlashDeliveryStateMachine.canUserCancel(ACCEPTED));
        assertFalse(FlashDeliveryStateMachine.canUserCancel(PICKED_UP));
        assertTrue(FlashDeliveryStateMachine.canAdminCancel(PICKED_UP));
        assertTrue(FlashDeliveryStateMachine.canAdminCancel(DELIVERED));
        assertFalse(FlashDeliveryStateMachine.canAdminCancel(COMPLETED));
    }
}
