<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_custom_cert_name(env='', region='', account='', certificate=None):
 """Generate a custom TLS Cert name based on a template. Args: env (str):
 Account environment name region (str):
 AWS Region. account (str):
 Account number for ARN. certificate (str):
 Name of SSL certificate. Returns: str: Fully qualified ARN for SSL certificate. None: Template doesn't exist. """

    cert_name = None
    template_kwargs = {'account': account, 'name': certificate}

    # TODO: Investigate moving this to a remote API, then fallback to local file if unable to connect
    try:
        rendered_template = get_template(template_file='infrastructure/iam/tlscert_naming.json.j2', **template_kwargs)
        tlscert_dict = json.loads(rendered_template)
    except ForemastTemplateNotFound:
        LOG.info('Unable to find TLS Cert Template...falling back to default logic...')
        return cert_name

    # TODO: Move to v1 method for check
    try:
        LOG.info("Attempting to find TLS Cert using TLS Cert Template v1 lookup...")
        cert_name = tlscert_dict[env][certificate]
        LOG.info("Found TLS certificate named %s under %s using TLS Cert Template v1", certificate, env)
    except KeyError:
        LOG.error("Unable to find TLS certificate named %s under %s using v1 TLS Cert Template.", certificate, env)

    # TODO: Move variable to consts
    # TODO: move to v2 method for check
    tls_services = ['iam', 'acm']
    if cert_name is None and all(service in tlscert_dict for service in tls_services):
        LOG.info("Attempting to find TLS Cert using TLS Cert Template v2 lookup...")
        if certificate in tlscert_dict['iam'][env]:
            cert_name = tlscert_dict['iam'][env][certificate]
            LOG.info("Found IAM TLS certificate named %s under %s using TLS Cert Template v2", certificate, env)
        elif certificate in tlscert_dict['acm'][region][env]:
            cert_name = tlscert_dict['acm'][region][env][certificate]
            LOG.info("Found ACM TLS certificate named %s under %s in %s using TLS Cert Template v2", certificate, env,
                     region)
        else:
            LOG.error(
                "Unable to find TLS certificate named %s under parent keys [ACM, IAM] %s in v2 TLS Cert Template.",
                certificate, env)

    return cert_name