/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   read_map_utils.c                                   :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: aortigos <aortigos@student.42malaga.com    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/12/04 10:07:52 by aortigos          #+#    #+#             */
/*   Updated: 2025/12/15 10:27:21 by aortigos         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "../../includes/cub3d.h"

int	check_tures_space_tab(char **texture2d, int count)
{
	int	i;

	i = -1;
	if (count != 6)
		return (0);
	while (++i < count)
		if (!is_valid_texture(texture2d[i]))
			return (ft_putstr_fd("texture error\n", 2), 0);
	return (1);
}

int	parse_rgb(char **texture2d)
{
	int		i;
	char	*ptr;

	i = 0;
	while (texture2d[i])
	{
		ptr = texture2d[i];
		while (ft_isspace(*ptr))
			ptr++;
		if (ptr[0] == 'F' || ptr[0] == 'C')
			if (count_comma(ptr) != 2 || !check_pos_cf(ptr))
				return (ft_putstr_fd("color error\n", 2), 0);
		i++;
	}
	return (1);
}

int	check_dup(t_data *m)
{
	int	i;
	int	j;

	i = 0;
	while (m->texture2d[i])
	{
		j = i + 1;
		while (m->texture2d[j])
		{
			if (!ft_strncmp(m->texture2d[i], m->texture2d[j], 2))
				return (ft_putstr_fd(ERR_MAP_DUP, 2), 0);
			j++;
		}
		i++;
	}
	return (1);
}

int	check_first_last_line(char **map)
{
	if (!map[0])
		return (ft_putstr_fd(ERR_MAP_INV, 2), 0);
	if (!line_around_one(map[0]) || !line_around_one(map[ft_arraylen(map) - 1]))
		return (ft_putstr_fd("one Y\n", 2), 0);
	return (1);
}

int	surrounded_by_one(char **map)
{
	int	i;
	int	flag;

	flag = 0;
	i = -1;
	while (map[++i])
		if (!is_surrounded(map[i]) || !is_validmap(map[i], &flag) || flag > 1)
			return (ft_putstr_fd("one X\n", 2), 0);
	if (flag == 0)
		return (ft_putstr_fd("no position map\n", 2), 0);
	return (1);
}
