from typing import Dict
from typing import Any


def prepare_issuer_subject_cell(asset_details: Dict[str, Any], key: str) -> str:
    """
    Retrieve nested properties of a key from asset details fetched in response to populate human readable

    :param asset_details: dictionary from which the properties are to be fetched
    :param key: the key whose nested properties and values are to be fetched
    :return: Human Readable of nested properties of the requested key to be populated on XSOAR
    """
    hr_cell_info = []

    # Fetch all keys
    common_name = asset_details.get(key, {}).get('common name', '')
    alternative_names = ', '.join(asset_details.get(f'{key}AlternativeNames', []))
    organization_name = asset_details.get(key, {}).get('organization', '')
    organization_unit = asset_details.get(key, {}).get('unit', '')
    locality = asset_details.get(key, {}).get('locale', '')
    state = asset_details.get(key, {}).get('state', '')
    country = asset_details.get(key, {}).get('country', '')
    if common_name:
        hr_cell_info.append(f'Common Name: {common_name}')
    if alternative_names:
        hr_cell_info.append(f'Alternate Names: {alternative_names}')
    if organization_name:
        hr_cell_info.append(f'Organization Name: {organization_name}')
    if organization_unit:
        hr_cell_info.append(f'Organization Unit: {organization_unit}')
    if locality:
        hr_cell_info.append(f'Locality: {locality}')
    if state:
        hr_cell_info.append(f'State: {state}')
    if country:
        hr_cell_info.append(f'Country: {country}')
    return '\n'.join(hr_cell_info)