SELECT 
        item.id,
        item.code,
        item.name,
        item.brand, 
        item.origin_country, 
        item.notes,
        item.avatar,
        item.avatarColor,
        COALESCE(item.avatarLetter, '') AS avatarLetter,
        item.avatarLetter,
        CONCAT(item.shelf_life) as shelf_life,
        CASE
        WHEN item.shelf_life > 0   THEN 'YES'
        ELSE 'NO'
        END AS shelf_life_check,
        item.temperature,
        CASE
        WHEN item.temperature = ''   THEN 'NO'
        ELSE 'YES'
        END AS temperature_check,
        CONCAT(
            '[',
                
                '{',
                    '"tableName":"chats"', 
                    ',"data":[',
                                  GROUP_CONCAT(
                                        DISTINCT(
                                        JSON_OBJECT(
                                            'id', chat_ia.id,
                                            'avatar', users.avatar,
                                            'question', chat_ia.question,
                                            'answare', chat_ia.answare,
                                            'userId', chat_ia.userId,
                                            'dateTime', chat_ia.dateTime         
                                        )

                                    ) SEPARATOR ','),
                            ']',
                '}',  
            
            ']'
         ) AS chats  
        FROM item 
        LEFT JOIN chat_ia ON item.id = chat_ia.entityId
        LEFT JOIN users ON chat_ia.userId = users.id
        WHERE item.deleted = '0' AND item.id = '658' ;