// File: /workspace/github_cpp_makefile_star2_O2/Karunika[P]Taxi_Agency_OODB/./src/TaxiAgency.cpp
// Function: TaxiAgency::book_taxi(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void TaxiAgency::book_taxi(string customer_uuid, string car_id){
    IndexInstance<Taxi> taxi;
    try{
        taxi = this->retrieve_taxi_by_id(car_id);
        if(taxi.data->available_number == 0)
            throw booking_unsuccessful("Taxi demanded Unavailable");
    }catch(invalid_argument e){
        throw booking_unsuccessful("Invalid Taxi id");
    };
    
    IndexInstance<Customer> customer = search_customer_by_uuid(customer_uuid);
    if(customer.data->getStatus() == ONSHIFT)
        throw booking_unsuccessful("Can't Book a Taxi while already ONSHIFT");

    if(customer.data->getBalance() < 12*taxi.data->fare_amount + 12*WaitingCharges)
        throw booking_unsuccessful("Not enough balance to book a Taxi");


    string driver_uuid;
    for(int i = 0; i < driver_db.size(); i++){
        if(driver_db[i].getStatus() == IDLE){
            taxi.data->available_number--;
            customer.data->toggle_customer_status();
            driver_uuid = driver_db[i].getUUID();
            driver_db[i].toggle_driver_status();
            Shift shift(customer_uuid, driver_uuid, car_id, taxi.data->fare_amount, WaitingCharges);
            shift.extend_tenure(12, 12);
            current_shifts.push_back(shift);
            return;
        }
    }
    throw booking_unsuccessful("Running out of drivers.");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
leaq -0xe0(%rbp), %rdi
movq %rdx, %rsi
callq 0x4360
leaq -0xe0(%rbp), %rsi
movq %rbx, %rdi
callq 0xe568
movq %rdx, %r15
leaq -0xe0(%rbp), %rdi
callq 0x4170
cmpl $0x0, 0x50(%r15)
je 0x1124b
leaq -0x100(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x4360
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf060
movq %rdx, %r13
leaq -0x100(%rbp), %rdi
callq 0x4170
movq %r13, %rdi
callq 0xc9ca
testl %eax, %eax
je 0x11283
movq %r12, -0x38(%rbp)
movq %r14, -0x30(%rbp)
movq %r13, %rdi
callq 0xc9d4
movl 0x88(%rbx), %ecx
movq %r15, -0x40(%rbp)
addl 0x48(%r15), %ecx
imull $0xc, %ecx, %ecx
cmpl %ecx, %eax
jl 0x1129e
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $-0x1
popq %r12
xorl %r14d, %r14d
movl $0x88, %r15d
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rax
subq %rdi, %rax
cqto
idivq %r15
incq %r12
cmpq %r12, %rax
jbe 0x11213
addq %r14, %rdi
callq 0xc7cc
addq %r15, %r14
cmpl $0x1, %eax
jne 0x110cb
movq -0x40(%rbp), %r15
decl 0x50(%r15)
movq %r13, %rdi
callq 0xc9ac
movq -0x38(%rbp), %r12
movq 0x18(%rbx), %rax
leaq (%rax,%r14), %rsi
addq $-0x48, %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x4360
leaq -0x60(%rbp), %rdi
leaq -0x1a0(%rbp), %r13
movq %r13, %rsi
callq 0x4300
movq %r13, %rdi
callq 0x4170
movq 0x18(%rbx), %rax
leaq (%rax,%r14), %rdi
addq $-0x88, %rdi
callq 0xc78c
leaq -0xc0(%rbp), %rdi
movq %r12, %rsi
callq 0x4360
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4360
movq -0x30(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x4360
movl 0x48(%r15), %r8d
movl 0x88(%rbx), %r9d
leaq -0x1a0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0xc9f4
leaq -0x80(%rbp), %rdi
callq 0x4170
leaq -0xa0(%rbp), %rdi
callq 0x4170
leaq -0xc0(%rbp), %rdi
callq 0x4170
leaq -0x1a0(%rbp), %rdi
pushq $0xc
popq %rdx
movl %edx, %esi
callq 0xd206
addq $0x48, %rbx
leaq -0x1a0(%rbp), %rsi
movq %rbx, %rdi
callq 0x12238
leaq -0x1a0(%rbp), %rdi
callq 0x12206
leaq -0x60(%rbp), %rdi
callq 0x4170
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x4190
leaq 0xc9ee(%rip), %rcx      # 0x1dc10
movq %rcx, (%rax)
leaq 0x49ee(%rip), %rcx      # 0x15c1a
movq %rcx, 0x8(%rax)
leaq 0xc9b1(%rip), %rsi      # 0x1dbe8
movq 0xcd8a(%rip), %rdx      # 0x1dfc8
movq %rax, %rdi
callq 0x4410
jmp 0x11395
pushq $0x10
popq %rdi
callq 0x4190
leaq 0xc9b6(%rip), %rcx      # 0x1dc10
movq %rcx, (%rax)
leaq 0x4942(%rip), %rcx      # 0x15ba6
movq %rcx, 0x8(%rax)
leaq 0xc979(%rip), %rsi      # 0x1dbe8
movq 0xcd52(%rip), %rdx      # 0x1dfc8
movq %rax, %rdi
callq 0x4410
jmp 0x11395
pushq $0x10
popq %rdi
callq 0x4190
leaq 0xc97e(%rip), %rcx      # 0x1dc10
movq %rcx, (%rax)
leaq 0x4934(%rip), %rcx      # 0x15bd0
jmp 0x112b7
pushq $0x10
popq %rdi
callq 0x4190
leaq 0xc963(%rip), %rcx      # 0x1dc10
movq %rcx, (%rax)
leaq 0x4941(%rip), %rcx      # 0x15bf8
movq %rcx, 0x8(%rax)
leaq 0xc926(%rip), %rsi      # 0x1dbe8
movq 0xccff(%rip), %rdx      # 0x1dfc8
movq %rax, %rdi
callq 0x4410
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x4170
jmp 0x112e2
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x4170
jmp 0x112f3
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x4170
jmp 0x113cb
jmp 0x113c8
jmp 0x113c8
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x113cf
jmp 0x11333
movq %rdx, %r14
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x4170
jmp 0x11339
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x113d4
movq %rbx, %rdi
callq 0x4310
leaq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0xbda4
movq %rbx, %rdi
callq 0x4150
pushq $0x10
popq %rdi
callq 0x4190
leaq 0xc89f(%rip), %rcx      # 0x1dc10
movq %rcx, (%rax)
leaq 0x4845(%rip), %rcx      # 0x15bc0
movq %rcx, 0x8(%rax)
leaq 0xc862(%rip), %rsi      # 0x1dbe8
movq 0xcc3b(%rip), %rdx      # 0x1dfc8
movq %rax, %rdi
callq 0x4410
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x44a0
callq 0x43e0
jmp 0x113d4
movq %rax, %rdi
callq 0xbc20
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x12206
jmp 0x113cb
jmp 0x113c8
jmp 0x113c8
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x4170
movq %rbx, %rdi
callq 0x4450