import logging
import requests
import json


def add_intersight_org(AUTH, RES_MOID, CLAIM_CONFIG):
    """ Add Intersight Organization """

    request_body = {
        "Name": CLAIM_CONFIG['partner_id'],
        "Description": "Org for " + CLAIM_CONFIG['partner_id'],
        "ResourceGroups": [
            {
                "ObjectType":"resource.Group",
                "Moid":RES_MOID
            }
        ]
    }
    logging.info(request_body)

    response = requests.post(
        CLAIM_CONFIG['intersight_base_url'] + 'organization/Organizations',
        data=json.dumps(request_body),
        auth=AUTH
    )
    logging.info(response.text)

    response_json = response.json()
    logging.info("ORGANIZATION: " + response_json["Moid"])

    return response_json["Moid"]