def parse_dhcpv6_leases_data(raw_data):
    if not raw_data.get("success") or not raw_data.get("data"):
        return [] 
    
    leases_data_string = raw_data.get("data")
    
    if not isinstance(leases_data_string, str) or not leases_data_string:
        return []

    lines = leases_data_string.strip().split('\n')
    
    if len(lines) < 3:
        return []

    lease_list = []
    
    for line in lines[2:]:
        line = line.strip()
        if not line:
            continue
            
        try:
            rest, type_val, pool, duid = line.rsplit(None, 3)
            prefix, state, middle_string = rest.split(None, 2)
            middle_parts = middle_string.split()
            last_comm = middle_parts[0] + " " + middle_parts[1]
            lease_exp = middle_parts[2] + " " + middle_parts[3]
            remaining = " ".join(middle_parts[4:])

            lease_info = {
                "prefix": prefix,
                "state": state,
                "last_communication": last_comm,
                "lease_expiration": lease_exp,
                "remaining": remaining,
                "type": type_val,
                "pool": pool,
                "duid": duid
            }
            lease_list.append(lease_info)
            
        except (ValueError, IndexError) as e:
            print(f"Warning: Could not parse DHCPv6 lease rule: {line} | Error: {e}")
            continue 
    
    return lease_list

def generate_dhcpv6_leases_json(lease_table):
    return {"data": lease_table}