import { Engine } from "/Scripts/types/engine";
import { BiomeData } from "/Scripts/types/host/server/data/biomedata";


/**
 * The width of a chunk
 */
export const CHUNK_WIDTH = 16;

/**
 * A voxel generated by a ChunkGenerator
 */
export interface GeneratedVoxel {

    /**
     * The id of the voxel type
     */
    type: number,

    /**
     * The weight of the voxel
     */
    weight: number,
}

/**
* Gets a voxel for a given position
* @param voxel The voxel to fill with values
* @param worldX The world x coordinate of the chunk
* @param worldY The world y coordinate of the chunk
* @param worldZ The world z coordinate of the chunk
* @param chunkX The chunk x coordinate
* @param chunkY The chunk y coordinate
* @param chunkZ The chunk z coordinate
* @param stride The stride of the data (this is used for LOD, it ranges 0->4 with 0 being the highest level of detail and 4 being the lowest)
* @param surfaceHeight The height of the surface at the given x,z coordinate
* @param terrainModel The terrain model
* @param surfaceBiome The surface biome
* @returns The voxel at the provided position
*/
export type VoxelFunction = (
    voxel: GeneratedVoxel,
    worldX: number, worldY: number, worldZ: number,
    chunkX: number, chunkY: number, chunkZ: number,
    stride: number,
    surfaceHeight: number,
    surfaceBiome: BiomeData
) => void;



/**
* Gets a chunk for a given world position
* @param worldX The world x coordinate of the chunk
* @param worldY The world y coordinate of the chunk
* @param worldZ The world z coordinate of the chunk
* @param stride The stride of the data (this is used for LOD, it ranges 0->4 with 0 being the highest level of detail and 4 being the lowest)
* @param surfaceHeight The height of the surface at the given x,z coordinate
* @param terrainModel The terrain model
* @param surfaceBiome The surface biome
* @returns The voxel at the provided position
*/
export type ChunkFunction = (
    worldX: number, worldY: number, worldZ: number,
    chunkX: number, chunkY: number, chunkZ: number,
    stride: number,
    surfaceHeight: number,
    surfaceBiome: BiomeData
) => number[][][];

/**
 * A chunk generator
 */
export interface ChunkGenerator {

    /**
     * Gets the tag for this generator
     * @returns The tag
     */
    getTag: () => string

    /**
     * Retrieves the elevation for the world at a given x,z coordinate
     * @param worldX The world x coordinate
     * @param worldZ The world z coordinate
     * @param chunkX The x coordinate of the chunk within the specified world coordinate
     * @param chunkZ The z coordinate of the chunk within the specified world coordinate
     * @returns The elevation at that specific position
     */
    getElevation: (worldX: number, worldZ: number, chunkX: number, chunkZ: number) => number

    /**
     * The function to get a voxel for a given position
     */
    getVoxelFunction: (engine: Engine) => VoxelFunction

}