package hws.hw3;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class ProductTest {

    @Test
    void testConstructor() {
        Product product = new Product(ProductType.CANDY, "M&Ms");

        assertEquals("M&Ms", product.getName(),
                "Product name should match the one provided in constructor");
        assertEquals(ProductType.CANDY, product.getType(),
                "Product type should match the one provided in constructor");
        assertEquals(0.40, product.getCost(), 0.0001,
                "Cost should match the default for CANDY");
        assertEquals(1.25, product.getPrice(), 0.0001,
                "Price should match the default for CANDY");
    }

    @Test
    void testGetters() {
        Product product = new Product(ProductType.CANDY, "M&Ms");
        assertEquals(0.40, product.getCost(), 0.0001,
                "Cost should match the default for CANDY");
        assertEquals(1.25, product.getPrice(), 0.0001,
                "Price should match the default for CANDY");
    }

    @Test
    void testSetCustomPrice() {
        Product product = new Product(ProductType.CHIPS, "Lays");

        product.setCustomPrice(2.00); // Already divisible by 0.25
        assertEquals(2.00, product.getPrice(), 0.0001,
                "Price should be set to argument value if already divisible by 0.25");
    }

    @Test
    void testSetCustomPriceNotDivisible() {
        Product product = new Product(ProductType.WATER, "Dasani");

        product.setCustomPrice(1.03);
        assertEquals(1.25, product.getPrice(), 0.0001,
                "Price should be rounded up to the next 0.25 increment");
    }


    @Test
    void testSetCustomPriceLessThanCost() {
        Product product = new Product(ProductType.SODA, "Fanta");

        product.setCustomPrice(0.20);
        assertEquals(0.50, product.getPrice(), 0.0001,
                "Price should be set to the next 0.25 increment above cost");
    }

    @Test
    void testSetCustomPriceEqualToCost() {
        Product product = new Product(ProductType.SODA, "Fanta");

        product.setCustomPrice(0.35);
        assertEquals(0.50, product.getPrice(), 0.0001,
                "Price equal to cost should round up to next valid price");
    }

    @Test
    void testToStringFormat() {
        Product product = new Product(ProductType.COOKIES, "Oreos");

        String expected = "COOKIES: Oreos Cost: 0.85 Price: 2.25.";
        assertEquals(expected, product.toString(),
                "toString() output does not match the expected format");
    }
}
