package com.ruoyi.app.flashdelivery.service;

import org.junit.jupiter.api.Test;

import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FlashDeliveryI18nContractTest {
    private static final List<String> FILES = List.of("messages.properties", "messages_zh_CN.properties",
            "messages_zh_TW.properties", "messages_en_US.properties", "messages_vi.properties");
    private static final List<String> KEYS = List.of(
            "flash.delivery.request.required", "flash.delivery.auth.required",
            "flash.delivery.client.request.id.invalid", "flash.delivery.note.too.long",
            "flash.delivery.service.type.invalid", "flash.delivery.service.unavailable",
            "flash.delivery.address.invalid", "flash.delivery.address.same",
            "flash.delivery.order.not.found", "flash.delivery.order.already.accepted",
            "flash.delivery.rider.required", "flash.delivery.proof.required",
            "flash.delivery.proof.url.invalid", "flash.delivery.proof.too.many",
            "flash.delivery.transition.not.allowed",
            "flash.delivery.cancel.reason.required", "flash.delivery.cancel.not.allowed",
            "flash.delivery.complete.not.allowed", "flash.delivery.state.changed",
            "flash.delivery.pricing.invalid", "flash.delivery.pricing.not.available",
            "flash.delivery.pricing.overlap", "flash.delivery.pricing.not.found",
            "flash.delivery.pricing.changed",
            "flash.delivery.delivery.type.invalid", "flash.delivery.item.invalid",
            "flash.delivery.tip.invalid", "flash.delivery.quote.changed",
            "flash.delivery.rider.exclusive.conflict",
            "address.access.denied", "address.data.invalid");

    @Test
    void everySupportedBundleContainsEveryFlashDeliveryMessage() throws Exception {
        for (String file : FILES) {
            Properties properties = new Properties();
            try (InputStream input = getClass().getClassLoader().getResourceAsStream("i18n/" + file)) {
                assertNotNull(input, file);
                properties.load(input);
            }
            for (String key : KEYS) {
                assertTrue(properties.containsKey(key), file + " missing " + key);
                assertTrue(!properties.getProperty(key).isBlank(), file + " blank " + key);
            }
        }
    }
}
