internal CompanyApiModel(int?activated, long?brandId, string comments, long?companyTypeId, CountryApiModel country, long?countryId, DateTimeOffset?creationTime, bool?disabledByPendingPayment, DateTimeOffset?disabledByPendingPaymentTime, string displayName, long?domainId, string email, DateTimeOffset?expirationDate, CompanyExtraInformationApiModel extraInformation, string firstname, FiscalRegionApiModel fiscalRegion, long?fiscalRegionId, long?id, string irpfModeCode, long?irpfModeId, bool?isDefault, DateTimeOffset?lastAccessTime, DateTimeOffset?lastUpdateTime, string lastname, string name, string nif, string organizationName, CompanyApiModelPaymentType?paymentType, string personName, bool?requiresConfiguration, bool?showRecargoEquivalencia, string timeZone, CompanyApiModelType?type, string uiCulture, string vatTypeCode, long?vatTypeId)
 {
     Activated                    = activated;
     BrandId                      = brandId;
     Comments                     = comments;
     CompanyTypeId                = companyTypeId;
     Country                      = country;
     CountryId                    = countryId;
     CreationTime                 = creationTime;
     DisabledByPendingPayment     = disabledByPendingPayment;
     DisabledByPendingPaymentTime = disabledByPendingPaymentTime;
     DisplayName                  = displayName;
     DomainId                     = domainId;
     Email            = email;
     ExpirationDate   = expirationDate;
     ExtraInformation = extraInformation;
     Firstname        = firstname;
     FiscalRegion     = fiscalRegion;
     FiscalRegionId   = fiscalRegionId;
     Id                      = id;
     IrpfModeCode            = irpfModeCode;
     IrpfModeId              = irpfModeId;
     IsDefault               = isDefault;
     LastAccessTime          = lastAccessTime;
     LastUpdateTime          = lastUpdateTime;
     Lastname                = lastname;
     Name                    = name;
     Nif                     = nif;
     OrganizationName        = organizationName;
     PaymentType             = paymentType;
     PersonName              = personName;
     RequiresConfiguration   = requiresConfiguration;
     ShowRecargoEquivalencia = showRecargoEquivalencia;
     TimeZone                = timeZone;
     Type                    = type;
     UiCulture               = uiCulture;
     VatTypeCode             = vatTypeCode;
     VatTypeId               = vatTypeId;
 }
        internal static CompanyApiModel DeserializeCompanyApiModel(XElement element)
        {
            int?            activated                    = default;
            long?           brandId                      = default;
            string          comments                     = default;
            long?           companyTypeId                = default;
            CountryApiModel country                      = default;
            long?           countryId                    = default;
            DateTimeOffset? creationTime                 = default;
            bool?           disabledByPendingPayment     = default;
            DateTimeOffset? disabledByPendingPaymentTime = default;
            string          displayName                  = default;
            long?           domainId                     = default;
            string          email          = default;
            DateTimeOffset? expirationDate = default;
            CompanyExtraInformationApiModel extraInformation = default;
            string firstname = default;
            FiscalRegionApiModel fiscalRegion                  = default;
            long?                      fiscalRegionId          = default;
            long?                      id                      = default;
            string                     irpfModeCode            = default;
            long?                      irpfModeId              = default;
            bool?                      isDefault               = default;
            DateTimeOffset?            lastAccessTime          = default;
            DateTimeOffset?            lastUpdateTime          = default;
            string                     lastname                = default;
            string                     name                    = default;
            string                     nif                     = default;
            string                     organizationName        = default;
            CompanyApiModelPaymentType?paymentType             = default;
            string                     personName              = default;
            bool?                      requiresConfiguration   = default;
            bool?                      showRecargoEquivalencia = default;
            string                     timeZone                = default;
            CompanyApiModelType?       type                    = default;
            string                     uiCulture               = default;
            string                     vatTypeCode             = default;
            long?                      vatTypeId               = default;

            if (element.Element("activated") is XElement activatedElement)
            {
                activated = (int?)activatedElement;
            }
            if (element.Element("brandId") is XElement brandIdElement)
            {
                brandId = (long?)brandIdElement;
            }
            if (element.Element("comments") is XElement commentsElement)
            {
                comments = (string)commentsElement;
            }
            if (element.Element("companyTypeId") is XElement companyTypeIdElement)
            {
                companyTypeId = (long?)companyTypeIdElement;
            }
            if (element.Element("country") is XElement countryElement)
            {
                country = CountryApiModel.DeserializeCountryApiModel(countryElement);
            }
            if (element.Element("countryId") is XElement countryIdElement)
            {
                countryId = (long?)countryIdElement;
            }
            if (element.Element("creationTime") is XElement creationTimeElement)
            {
                creationTime = creationTimeElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("disabledByPendingPayment") is XElement disabledByPendingPaymentElement)
            {
                disabledByPendingPayment = (bool?)disabledByPendingPaymentElement;
            }
            if (element.Element("disabledByPendingPaymentTime") is XElement disabledByPendingPaymentTimeElement)
            {
                disabledByPendingPaymentTime = disabledByPendingPaymentTimeElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("displayName") is XElement displayNameElement)
            {
                displayName = (string)displayNameElement;
            }
            if (element.Element("domainId") is XElement domainIdElement)
            {
                domainId = (long?)domainIdElement;
            }
            if (element.Element("email") is XElement emailElement)
            {
                email = (string)emailElement;
            }
            if (element.Element("expirationDate") is XElement expirationDateElement)
            {
                expirationDate = expirationDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("extraInformation") is XElement extraInformationElement)
            {
                extraInformation = CompanyExtraInformationApiModel.DeserializeCompanyExtraInformationApiModel(extraInformationElement);
            }
            if (element.Element("firstname") is XElement firstnameElement)
            {
                firstname = (string)firstnameElement;
            }
            if (element.Element("fiscalRegion") is XElement fiscalRegionElement)
            {
                fiscalRegion = FiscalRegionApiModel.DeserializeFiscalRegionApiModel(fiscalRegionElement);
            }
            if (element.Element("fiscalRegionId") is XElement fiscalRegionIdElement)
            {
                fiscalRegionId = (long?)fiscalRegionIdElement;
            }
            if (element.Element("id") is XElement idElement)
            {
                id = (long?)idElement;
            }
            if (element.Element("irpfModeCode") is XElement irpfModeCodeElement)
            {
                irpfModeCode = (string)irpfModeCodeElement;
            }
            if (element.Element("irpfModeId") is XElement irpfModeIdElement)
            {
                irpfModeId = (long?)irpfModeIdElement;
            }
            if (element.Element("isDefault") is XElement isDefaultElement)
            {
                isDefault = (bool?)isDefaultElement;
            }
            if (element.Element("lastAccessTime") is XElement lastAccessTimeElement)
            {
                lastAccessTime = lastAccessTimeElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("lastUpdateTime") is XElement lastUpdateTimeElement)
            {
                lastUpdateTime = lastUpdateTimeElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("lastname") is XElement lastnameElement)
            {
                lastname = (string)lastnameElement;
            }
            if (element.Element("name") is XElement nameElement)
            {
                name = (string)nameElement;
            }
            if (element.Element("nif") is XElement nifElement)
            {
                nif = (string)nifElement;
            }
            if (element.Element("organizationName") is XElement organizationNameElement)
            {
                organizationName = (string)organizationNameElement;
            }
            if (element.Element("paymentType") is XElement paymentTypeElement)
            {
                paymentType = new CompanyApiModelPaymentType(paymentTypeElement.Value);
            }
            if (element.Element("personName") is XElement personNameElement)
            {
                personName = (string)personNameElement;
            }
            if (element.Element("requiresConfiguration") is XElement requiresConfigurationElement)
            {
                requiresConfiguration = (bool?)requiresConfigurationElement;
            }
            if (element.Element("showRecargoEquivalencia") is XElement showRecargoEquivalenciaElement)
            {
                showRecargoEquivalencia = (bool?)showRecargoEquivalenciaElement;
            }
            if (element.Element("timeZone") is XElement timeZoneElement)
            {
                timeZone = (string)timeZoneElement;
            }
            if (element.Element("type") is XElement typeElement)
            {
                type = new CompanyApiModelType(typeElement.Value);
            }
            if (element.Element("uiCulture") is XElement uiCultureElement)
            {
                uiCulture = (string)uiCultureElement;
            }
            if (element.Element("vatTypeCode") is XElement vatTypeCodeElement)
            {
                vatTypeCode = (string)vatTypeCodeElement;
            }
            if (element.Element("vatTypeId") is XElement vatTypeIdElement)
            {
                vatTypeId = (long?)vatTypeIdElement;
            }
            return(new CompanyApiModel(activated, brandId, comments, companyTypeId, country, countryId, creationTime, disabledByPendingPayment, disabledByPendingPaymentTime, displayName, domainId, email, expirationDate, extraInformation, firstname, fiscalRegion, fiscalRegionId, id, irpfModeCode, irpfModeId, isDefault, lastAccessTime, lastUpdateTime, lastname, name, nif, organizationName, paymentType, personName, requiresConfiguration, showRecargoEquivalencia, timeZone, type, uiCulture, vatTypeCode, vatTypeId));
        }
        internal static CompanyApiModel DeserializeCompanyApiModel(JsonElement element)
        {
            Optional <int>             activated                    = default;
            Optional <long>            brandId                      = default;
            Optional <string>          comments                     = default;
            Optional <long>            companyTypeId                = default;
            Optional <CountryApiModel> country                      = default;
            Optional <long>            countryId                    = default;
            Optional <DateTimeOffset>  creationTime                 = default;
            Optional <bool>            disabledByPendingPayment     = default;
            Optional <DateTimeOffset>  disabledByPendingPaymentTime = default;
            Optional <string>          displayName                  = default;
            Optional <long>            domainId                     = default;
            Optional <string>          email          = default;
            Optional <DateTimeOffset>  expirationDate = default;
            Optional <CompanyExtraInformationApiModel> extraInformation = default;
            Optional <string> firstname = default;
            Optional <FiscalRegionApiModel> fiscalRegion                  = default;
            Optional <long>                       fiscalRegionId          = default;
            Optional <long>                       id                      = default;
            Optional <string>                     irpfModeCode            = default;
            Optional <long>                       irpfModeId              = default;
            Optional <bool>                       isDefault               = default;
            Optional <DateTimeOffset>             lastAccessTime          = default;
            Optional <DateTimeOffset>             lastUpdateTime          = default;
            Optional <string>                     lastname                = default;
            Optional <string>                     name                    = default;
            Optional <string>                     nif                     = default;
            Optional <string>                     organizationName        = default;
            Optional <CompanyApiModelPaymentType> paymentType             = default;
            Optional <string>                     personName              = default;
            Optional <bool>                       requiresConfiguration   = default;
            Optional <bool>                       showRecargoEquivalencia = default;
            Optional <string>                     timeZone                = default;
            Optional <CompanyApiModelType>        type                    = default;
            Optional <string>                     uiCulture               = default;
            Optional <string>                     vatTypeCode             = default;
            Optional <long>                       vatTypeId               = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("activated"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    activated = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("brandId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    brandId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("comments"))
                {
                    comments = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("companyTypeId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    companyTypeId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("country"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    country = CountryApiModel.DeserializeCountryApiModel(property.Value);
                    continue;
                }
                if (property.NameEquals("countryId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    countryId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("creationTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    creationTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("disabledByPendingPayment"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    disabledByPendingPayment = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("disabledByPendingPaymentTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    disabledByPendingPaymentTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("displayName"))
                {
                    displayName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("domainId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    domainId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("email"))
                {
                    email = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("expirationDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    expirationDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("extraInformation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    extraInformation = CompanyExtraInformationApiModel.DeserializeCompanyExtraInformationApiModel(property.Value);
                    continue;
                }
                if (property.NameEquals("firstname"))
                {
                    firstname = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("fiscalRegion"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    fiscalRegion = FiscalRegionApiModel.DeserializeFiscalRegionApiModel(property.Value);
                    continue;
                }
                if (property.NameEquals("fiscalRegionId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    fiscalRegionId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    id = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("irpfModeCode"))
                {
                    irpfModeCode = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("irpfModeId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    irpfModeId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("isDefault"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    isDefault = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("lastAccessTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    lastAccessTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastUpdateTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    lastUpdateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastname"))
                {
                    lastname = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("nif"))
                {
                    nif = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("organizationName"))
                {
                    organizationName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("paymentType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    paymentType = new CompanyApiModelPaymentType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("personName"))
                {
                    personName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("requiresConfiguration"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    requiresConfiguration = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("showRecargoEquivalencia"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    showRecargoEquivalencia = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("timeZone"))
                {
                    timeZone = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    type = new CompanyApiModelType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("uiCulture"))
                {
                    uiCulture = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("vatTypeCode"))
                {
                    vatTypeCode = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("vatTypeId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    vatTypeId = property.Value.GetInt64();
                    continue;
                }
            }
            return(new CompanyApiModel(Optional.ToNullable(activated), Optional.ToNullable(brandId), comments.Value, Optional.ToNullable(companyTypeId), country.Value, Optional.ToNullable(countryId), Optional.ToNullable(creationTime), Optional.ToNullable(disabledByPendingPayment), Optional.ToNullable(disabledByPendingPaymentTime), displayName.Value, Optional.ToNullable(domainId), email.Value, Optional.ToNullable(expirationDate), extraInformation.Value, firstname.Value, fiscalRegion.Value, Optional.ToNullable(fiscalRegionId), Optional.ToNullable(id), irpfModeCode.Value, Optional.ToNullable(irpfModeId), Optional.ToNullable(isDefault), Optional.ToNullable(lastAccessTime), Optional.ToNullable(lastUpdateTime), lastname.Value, name.Value, nif.Value, organizationName.Value, Optional.ToNullable(paymentType), personName.Value, Optional.ToNullable(requiresConfiguration), Optional.ToNullable(showRecargoEquivalencia), timeZone.Value, Optional.ToNullable(type), uiCulture.Value, vatTypeCode.Value, Optional.ToNullable(vatTypeId)));
        }