const initConsole = require('./src/index.js');
const fs = require('fs');
const express = require('express');

const init = () => {
    function func() {
        console.log('this is a function')
    }

    const test = {
        boolean: true,
        number: 1,
        string: '1',
        null: null,
        undefined: undefined,
        func: function () {
            console.log('this is a anonymous function')
        },
        object: {
            key: 'key',
            value: 'value'
        },
        array: [1, 2, 3, 4, 5, [123, { a: 1, func }], 1]

    }

    console.log(test)
    // console.log(a)

    function fun1() {
        console.log('this is fun1')
    }

    const fun2 = () => {
        console.log('this is fun2')
    }

    class Demo {
        constructor(){
             this.x = 1;
        }
        add (a,b){
            return a+b
        }
    }
    console.log('=== primitive logs ===', true, 123, 'hello', null, undefined)
    console.log('=== nested object ===', { a: 1, b: { c: [1, 2, 3] } })
    console.log('=== array mix ===', [1, '2', { x: 3 }, [4, 5]])
    console.log('=== function refs ===', fun1, fun2, func)
    console.log('=== date & regex ===', new Date('2024-01-01'), /node-console/gi)
    console.log('=== big object ===', { test, a:NaN,time: Date.now(), info: { env: process.env.NODE_ENV } })
    console.log('=== long string ===', 'qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop')
    console.log('=== promise ===', Promise.resolve({ ok: true }))
    console.log('=== promise ===', new Promise(resolve=>{}))
    console.log('=== map ===', new Map([["c", 1],["a", 1], ["b", { nested: true }]]))
    console.log('=== set ===', new Set([1, 2, 3, "x"]))
    console.log('=== symbol ===', Symbol('demo'))
    console.log('=== bigint ===', BigInt(9007199254740991))
    console.log('=== class instance ===', new Demo())
    console.log('=== error ===', new Error('This is an error message'))

    // Express 请求体打印示例（运行前确保已安装 express）
    const app = express();
    app.use(express.json());
    app.post('/echo', (req, res) => {
        console.log('=== express req ===', req)
        console.log('=== express res ===', res)
        res.json({ ok: true, received: req.body });
    });
    app.listen(3000, () => {
        console.log('=== express server ===', 'http://localhost:3000/echo')
        setTimeout(() => {
            fetch('http://localhost:3000/echo', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                    user: 'demo',
                    tags: ['node-console', 'express'],
                    meta: { from: 'example' }
                })
            })
                .then(res => res.json())
                .then(data => console.log('=== express response ===', data))
                .catch(err => console.log('=== express request error ===', err.message))
        }, 200)
    });
    // console.log('=== fs ===', fs)
    // console.log(fun1)
    // console.log(fun2)
    // console.log(function (){
    //     console.log('this is a anonymous function')
    // })

}

initConsole(init,{dev:false})



