package com.ruoyi.system.domain;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

class InfoUserDeliveryTypeTest {

    @Test
    void blankDeliveryTypeSupportsEverythingForLegacyRiders() {
        InfoUser rider = new InfoUser();
        assertTrue(rider.supportsDeliveryType("FOOD"));
        assertTrue(rider.supportsDeliveryType("FLASH"));
        rider.setDeliveryType("   ");
        assertTrue(rider.supportsDeliveryType("FLASH"));
    }

    @Test
    void selectedTypesControlAccess() {
        InfoUser rider = new InfoUser();
        rider.setDeliveryType("FOOD");
        assertTrue(rider.supportsDeliveryType("FOOD"));
        assertFalse(rider.supportsDeliveryType("FLASH"));
        rider.setDeliveryType("FLASH,FOOD");
        assertTrue(rider.supportsDeliveryType("FLASH"));
        assertTrue(rider.supportsDeliveryType("food"));
    }

    @Test
    void normalizeTrimsUpperCasesAndDeduplicates() {
        assertNull(InfoUser.normalizeDeliveryTypes(null));
        assertNull(InfoUser.normalizeDeliveryTypes("   "));
        assertEquals("FOOD", InfoUser.normalizeDeliveryTypes(" food "));
        assertEquals("FLASH,FOOD", InfoUser.normalizeDeliveryTypes("flash, FOOD ,flash"));
    }

    @Test
    void normalizeRejectsValuesWithoutAnyKnownType() {
        assertThrows(IllegalArgumentException.class, () -> InfoUser.normalizeDeliveryTypes("TAXI"));
        assertThrows(IllegalArgumentException.class, () -> InfoUser.normalizeDeliveryTypes(" , "));
    }
}
