// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.mediaservices.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

/** Specifies a configuration for FairPlay licenses. */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@odata.type")
@JsonTypeName("#Microsoft.Media.ContentKeyPolicyFairPlayConfiguration")
@Fluent
public final class ContentKeyPolicyFairPlayConfiguration extends ContentKeyPolicyConfiguration {
    /*
     * The key that must be used as FairPlay Application Secret key. This needs to be base64 encoded.
     */
    @JsonProperty(value = "ask", required = true)
    private byte[] ask;

    /*
     * The password encrypting FairPlay certificate in PKCS 12 (pfx) format.
     */
    @JsonProperty(value = "fairPlayPfxPassword", required = true)
    private String fairPlayPfxPassword;

    /*
     * The Base64 representation of FairPlay certificate in PKCS 12 (pfx) format (including private key).
     */
    @JsonProperty(value = "fairPlayPfx", required = true)
    private String fairPlayPfx;

    /*
     * The rental and lease key type.
     */
    @JsonProperty(value = "rentalAndLeaseKeyType", required = true)
    private ContentKeyPolicyFairPlayRentalAndLeaseKeyType rentalAndLeaseKeyType;

    /*
     * The rental duration. Must be greater than or equal to 0.
     */
    @JsonProperty(value = "rentalDuration", required = true)
    private long rentalDuration;

    /*
     * Offline rental policy
     */
    @JsonProperty(value = "offlineRentalConfiguration")
    private ContentKeyPolicyFairPlayOfflineRentalConfiguration offlineRentalConfiguration;

    /** Creates an instance of ContentKeyPolicyFairPlayConfiguration class. */
    public ContentKeyPolicyFairPlayConfiguration() {
    }

    /**
     * Get the ask property: The key that must be used as FairPlay Application Secret key. This needs to be base64
     * encoded.
     *
     * @return the ask value.
     */
    public byte[] ask() {
        return CoreUtils.clone(this.ask);
    }

    /**
     * Set the ask property: The key that must be used as FairPlay Application Secret key. This needs to be base64
     * encoded.
     *
     * @param ask the ask value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withAsk(byte[] ask) {
        this.ask = CoreUtils.clone(ask);
        return this;
    }

    /**
     * Get the fairPlayPfxPassword property: The password encrypting FairPlay certificate in PKCS 12 (pfx) format.
     *
     * @return the fairPlayPfxPassword value.
     */
    public String fairPlayPfxPassword() {
        return this.fairPlayPfxPassword;
    }

    /**
     * Set the fairPlayPfxPassword property: The password encrypting FairPlay certificate in PKCS 12 (pfx) format.
     *
     * @param fairPlayPfxPassword the fairPlayPfxPassword value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withFairPlayPfxPassword(String fairPlayPfxPassword) {
        this.fairPlayPfxPassword = fairPlayPfxPassword;
        return this;
    }

    /**
     * Get the fairPlayPfx property: The Base64 representation of FairPlay certificate in PKCS 12 (pfx) format
     * (including private key).
     *
     * @return the fairPlayPfx value.
     */
    public String fairPlayPfx() {
        return this.fairPlayPfx;
    }

    /**
     * Set the fairPlayPfx property: The Base64 representation of FairPlay certificate in PKCS 12 (pfx) format
     * (including private key).
     *
     * @param fairPlayPfx the fairPlayPfx value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withFairPlayPfx(String fairPlayPfx) {
        this.fairPlayPfx = fairPlayPfx;
        return this;
    }

    /**
     * Get the rentalAndLeaseKeyType property: The rental and lease key type.
     *
     * @return the rentalAndLeaseKeyType value.
     */
    public ContentKeyPolicyFairPlayRentalAndLeaseKeyType rentalAndLeaseKeyType() {
        return this.rentalAndLeaseKeyType;
    }

    /**
     * Set the rentalAndLeaseKeyType property: The rental and lease key type.
     *
     * @param rentalAndLeaseKeyType the rentalAndLeaseKeyType value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withRentalAndLeaseKeyType(
        ContentKeyPolicyFairPlayRentalAndLeaseKeyType rentalAndLeaseKeyType) {
        this.rentalAndLeaseKeyType = rentalAndLeaseKeyType;
        return this;
    }

    /**
     * Get the rentalDuration property: The rental duration. Must be greater than or equal to 0.
     *
     * @return the rentalDuration value.
     */
    public long rentalDuration() {
        return this.rentalDuration;
    }

    /**
     * Set the rentalDuration property: The rental duration. Must be greater than or equal to 0.
     *
     * @param rentalDuration the rentalDuration value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withRentalDuration(long rentalDuration) {
        this.rentalDuration = rentalDuration;
        return this;
    }

    /**
     * Get the offlineRentalConfiguration property: Offline rental policy.
     *
     * @return the offlineRentalConfiguration value.
     */
    public ContentKeyPolicyFairPlayOfflineRentalConfiguration offlineRentalConfiguration() {
        return this.offlineRentalConfiguration;
    }

    /**
     * Set the offlineRentalConfiguration property: Offline rental policy.
     *
     * @param offlineRentalConfiguration the offlineRentalConfiguration value to set.
     * @return the ContentKeyPolicyFairPlayConfiguration object itself.
     */
    public ContentKeyPolicyFairPlayConfiguration withOfflineRentalConfiguration(
        ContentKeyPolicyFairPlayOfflineRentalConfiguration offlineRentalConfiguration) {
        this.offlineRentalConfiguration = offlineRentalConfiguration;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        super.validate();
        if (ask() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property ask in model ContentKeyPolicyFairPlayConfiguration"));
        }
        if (fairPlayPfxPassword() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property fairPlayPfxPassword in model"
                            + " ContentKeyPolicyFairPlayConfiguration"));
        }
        if (fairPlayPfx() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property fairPlayPfx in model ContentKeyPolicyFairPlayConfiguration"));
        }
        if (rentalAndLeaseKeyType() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property rentalAndLeaseKeyType in model"
                            + " ContentKeyPolicyFairPlayConfiguration"));
        }
        if (offlineRentalConfiguration() != null) {
            offlineRentalConfiguration().validate();
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ContentKeyPolicyFairPlayConfiguration.class);
}
