package com.tiedup.remake.client.renderer.obj;

import org.jetbrains.annotations.Nullable;

/**
 * Immutable record representing a material from an MTL file.
 * Contains the material name, diffuse color (Kd), and optional diffuse texture (map_Kd).
 */
public record ObjMaterial(
    String name,
    float r,
    float g,
    float b,
    @Nullable String texturePath
) {
    /**
     * Default white material used when no material is specified.
     */
    public static final ObjMaterial DEFAULT = new ObjMaterial(
        "default",
        1.0f,
        1.0f,
        1.0f,
        null
    );

    /**
     * Create a material with just color (no texture).
     */
    public ObjMaterial(String name, float r, float g, float b) {
        this(name, r, g, b, null);
    }

    /**
     * Create a material with grayscale color.
     */
    public static ObjMaterial ofGrayscale(String name, float value) {
        return new ObjMaterial(name, value, value, value, null);
    }

    /**
     * Check if this material has a diffuse texture.
     */
    public boolean hasTexture() {
        return texturePath != null && !texturePath.isEmpty();
    }

    /**
     * Get the color as a packed ARGB int (with full alpha).
     */
    public int toARGB() {
        int ri = (int) (r * 255) & 0xFF;
        int gi = (int) (g * 255) & 0xFF;
        int bi = (int) (b * 255) & 0xFF;
        return 0xFF000000 | (ri << 16) | (gi << 8) | bi;
    }
}
