# Copyright (c) 2024 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com
from typing import Optional, Tuple

from czid.czrn.internal import billing_lineitem


def get_resource_global_name_components(lineitem_fields) -> Tuple[str, Optional[str], str, str]:
    raw_resource_id = lineitem_fields.get('lineitem_resourceid')

    resource_id = raw_resource_id.strip() if raw_resource_id else None
    product_code = (lineitem_fields.get('lineitem_productcode') or '').lower()
    product_region = billing_lineitem.get_region_from_billing_fields(lineitem_fields)
    account_id = billing_lineitem.get_account_id_from_billing_fields(lineitem_fields)

    return product_code, product_region, account_id, resource_id
