import struct


def get_job_trace(job_id, username, submit_time, duration, wclimit,tasks,
                  cpus_per_task,tasks_per_node, qosname, partition, account,
                  reservation="", dependency="", workflow_manifest=None):
    """Returns the struct packing of the job data. Format:
        typedef struct job_trace {
            int job_id;
            char username[MAX_USERNAME_LEN];
            long int submit; /* relative or absolute? */
            int duration;
            int wclimit; (in minutes)
            int tasks;
            char qosname[MAX_QOSNAME];
            char partition[MAX_QOSNAME];
            char account[MAX_QOSNAME];
            int cpus_per_task;
            int tasks_per_node;
            char reservation[MAX_RSVNAME];
            char dependency[MAX_RSVNAME];
            struct job_trace *next;
        } job_trace_t;
        
        MAX_USERNAME_LEN, MAX_QOSNAME, MAX_RSVNAME = 30
""" 
    if workflow_manifest is None:

        buf=struct.pack("i30sliii30s30s30sii30s1024sP",job_id,
                        bytearray(username, encoding="utf-8"),
                        submit_time, 
                        duration, wclimit, tasks,
                        bytearray(qosname, encoding="utf-8"),
                        bytearray(partition, encoding="utf-8"),
                        bytearray(account, encoding="utf-8"), 
                        cpus_per_task, tasks_per_node,
                        bytearray(reservation, encoding="utf-8"),
                        bytearray(dependency, encoding="utf-8"),
                        0)
    else:
        buf=struct.pack("li30sliii30s30s30sii30s1024sP1024sP",
                        0xFFFFFFFF,
                        job_id,
                        bytearray(username,encoding="utf-8"),
                        submit_time, 
                        duration, int(wclimit), tasks,
                        bytearray(qosname,encoding="utf-8"),
                        bytearray(partition, encoding="utf-8"),
                        bytearray(account, encoding="utf-8"), 
                        cpus_per_task, tasks_per_node,
                        bytearray(reservation, encoding="utf-8"),
                        bytearray(dependency, encoding="utf-8"),
                        0, bytearray(workflow_manifest, encoding="utf-8"),
                        0)
    
   
    return buf