// File: trisolaris233[P]httpc/src/main2.cpp
// Function: main
int main(int argc, char* argv[]) {

    httpc::Server server(
        "127.0.0.1", 
        std::string(argv[1]), 
        "/home/sakakiyukiho/dev/cpp/httpc/static"
    );
    // constexpr auto GET = httpc::HttpMethodEnum::GET;
    // constexpr auto POST = httpc::HttpMethodEnum::POST;
    server.AddRouter<httpc::HttpMethodEnum::GET, httpc::HttpMethodEnum::POST>
    ("/root", [](Request& req, Response& res) {
        
        httpc::debug().dg("bussiness filesize received => ").dg(req.GetFileSize()).lf();
        if (req.GetFileSize() != 0) {
            // req.DenyNextFile(); // refuse to recv next file
            req.RecvNextFile();
        } else {
            // std::cout << "53?" << std::endl;
            res.RenderString("hello, world");
        }
        if (req.RecvComplete() && req.RecvSuccessfully()) {
            // std::cout << "go render" << std::endl;
            res.RenderString(req.GetFiles()[0].GetContent());
        }
    });
    server.AddRouter("/root/*",[](Request&, Response& res) {
        res.RenderString("hello, root");
    });
    server.AddRouter("/static_file", [&server](Request& req, Response& res) {
        res.RenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    });

    // server.AddRouter("/", [](Request&, Response& res){
    //     //std::cout << "enter bussiness" << std::endl;
    //     res.RenderString("hello world");
    //     httpc::debug().dg("root").lf();
    // });
    // server.AddRouter("/index/?", [](Request&, Response& res) {
    //     std::cout << "enter /index?" << std::endl;
    //     res.RenderString("This is the index page of router /index?");
    // });
    // server.AddRouter(
    //     std::regex("/[^/]+/[^/]+/[^/]+/{0,1}"),
    //     [](Request&, Response& res) {
    //         std::cout << "enter regex" << std::endl;
    //         res.RenderString("If you see this page that means you've entered /*/*[/] route");
    //     });
    // server.AddRouter("/index.html", [&server](Request&, Response& res) {
    //     res.RenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    // });
    // server.AddRouter("/index2.html", [&server](Request&, Response& res) {
    //     res.AsyncRenderFromStaticFile(server.GetDocumentRoot() + "/index.html");
    // });

    server.Start();

    for(;;) {}
    // testDefaultResponse();
    return 0;
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0xab40
movq -0x240(%rbp), %rdx
leaq 0x4e16d(%rip), %rsi     # 0x59557
leaq -0x150(%rbp), %rdi
callq 0xf9c0
jmp 0xb3f8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x250(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0xab40
movq -0x250(%rbp), %rsi
movq -0x248(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0xf9c0
jmp 0xb436
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0xab40
movq -0x258(%rbp), %rdx
leaq 0x4e10a(%rip), %rsi     # 0x59561
leaq -0x1b0(%rbp), %rdi
callq 0xf9c0
jmp 0xb465
callq 0x55680
movq %rax, %r8
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x188(%rbp), %rdx
leaq -0x1b0(%rbp), %rcx
callq 0xfa70
jmp 0xb490
leaq -0x1b0(%rbp), %rdi
callq 0xa450
leaq -0x1b1(%rbp), %rdi
callq 0xa740
leaq -0x188(%rbp), %rdi
callq 0xa450
leaq -0x189(%rbp), %rdi
callq 0xa740
leaq -0x150(%rbp), %rdi
callq 0xa450
leaq -0x151(%rbp), %rdi
callq 0xa740
leaq -0x1d9(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0xab40
movq -0x260(%rbp), %rdx
leaq 0x4e090(%rip), %rsi     # 0x59589
leaq -0x1d8(%rbp), %rdi
callq 0xf9c0
jmp 0xb507
leaq -0x130(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
leaq -0x1da(%rbp), %rdx
callq 0xb7b0
jmp 0xb523
leaq -0x1d8(%rbp), %rdi
callq 0xa450
leaq -0x1d9(%rbp), %rdi
callq 0xa740
leaq -0x201(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0xab40
movq -0x268(%rbp), %rdx
leaq 0x4e033(%rip), %rsi     # 0x5958f
leaq -0x200(%rbp), %rdi
callq 0xf9c0
jmp 0xb56a
leaq -0x130(%rbp), %rdi
leaq -0x200(%rbp), %rsi
leaq -0x202(%rbp), %rdx
callq 0xb7f0
jmp 0xb586
leaq -0x200(%rbp), %rdi
callq 0xa450
leaq -0x201(%rbp), %rdi
callq 0xa740
leaq -0x229(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0xab40
movq -0x270(%rbp), %rdx
leaq 0x4dfd8(%rip), %rsi     # 0x59597
leaq -0x228(%rbp), %rdi
callq 0xf9c0
jmp 0xb5cd
leaq -0x130(%rbp), %rdi
movq %rdi, -0x238(%rbp)
leaq -0x228(%rbp), %rsi
leaq -0x238(%rbp), %rdx
callq 0xb830
jmp 0xb5f0
leaq -0x228(%rbp), %rdi
callq 0xa450
leaq -0x229(%rbp), %rdi
callq 0xa740
leaq -0x130(%rbp), %rdi
callq 0xfd40
jmp 0xb616
jmp 0xb618
jmp 0xb618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb6a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb68c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb674
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xa450
leaq -0x1b1(%rbp), %rdi
callq 0xa740
leaq -0x188(%rbp), %rdi
callq 0xa450
leaq -0x189(%rbp), %rdi
callq 0xa740
leaq -0x150(%rbp), %rdi
callq 0xa450
leaq -0x151(%rbp), %rdi
callq 0xa740
jmp 0xb796
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb6e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xa450
leaq -0x1d9(%rbp), %rdi
callq 0xa740
jmp 0xb78a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb72a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x200(%rbp), %rdi
callq 0xa450
leaq -0x201(%rbp), %rdi
callq 0xa740
jmp 0xb78a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xb76a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x228(%rbp), %rdi
callq 0xa450
leaq -0x229(%rbp), %rdi
callq 0xa740
jmp 0xb78a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x130(%rbp), %rdi
callq 0xfd90
movq -0x160(%rbp), %rdi
callq 0xab10
nopw %cs:(%rax,%rax)