<?php

namespace AsyncAws\Iam\ValueObject;

use AsyncAws\Core\Exception\InvalidArgument;
use AsyncAws\Iam\Enum\StatusType;

/**
 * Contains the details of a service-specific credential.
 */
final class ServiceSpecificCredential
{
    /**
     * The date and time, in ISO 8601 date-time format [^1], when the service-specific credential were created.
     *
     * [^1]: http://www.iso.org/iso/iso8601
     *
     * @var \DateTimeImmutable
     */
    private $createDate;

    /**
     * The date and time when the service specific credential expires. This field is only present for Bedrock API keys that
     * were created with an expiration period.
     *
     * @var \DateTimeImmutable|null
     */
    private $expirationDate;

    /**
     * The name of the service associated with the service-specific credential.
     *
     * @var string
     */
    private $serviceName;

    /**
     * The generated user name for the service-specific credential. This value is generated by combining the IAM user's name
     * combined with the ID number of the Amazon Web Services account, as in `jane-at-123456789012`, for example. This value
     * cannot be configured by the user.
     *
     * @var string|null
     */
    private $serviceUserName;

    /**
     * The generated password for the service-specific credential.
     *
     * @var string|null
     */
    private $servicePassword;

    /**
     * For Bedrock API keys, this is the public portion of the credential that includes the IAM user name and a suffix
     * containing version and creation information.
     *
     * @var string|null
     */
    private $serviceCredentialAlias;

    /**
     * For Bedrock API keys, this is the secret portion of the credential that should be used to authenticate API calls.
     * This value is returned only when the credential is created.
     *
     * @var string|null
     */
    private $serviceCredentialSecret;

    /**
     * The unique identifier for the service-specific credential.
     *
     * @var string
     */
    private $serviceSpecificCredentialId;

    /**
     * The name of the IAM user associated with the service-specific credential.
     *
     * @var string
     */
    private $userName;

    /**
     * The status of the service-specific credential. `Active` means that the key is valid for API calls, while `Inactive`
     * means it is not.
     *
     * @var StatusType::*
     */
    private $status;

    /**
     * @param array{
     *   CreateDate: \DateTimeImmutable,
     *   ExpirationDate?: \DateTimeImmutable|null,
     *   ServiceName: string,
     *   ServiceUserName?: string|null,
     *   ServicePassword?: string|null,
     *   ServiceCredentialAlias?: string|null,
     *   ServiceCredentialSecret?: string|null,
     *   ServiceSpecificCredentialId: string,
     *   UserName: string,
     *   Status: StatusType::*,
     * } $input
     */
    public function __construct(array $input)
    {
        $this->createDate = $input['CreateDate'] ?? $this->throwException(new InvalidArgument('Missing required field "CreateDate".'));
        $this->expirationDate = $input['ExpirationDate'] ?? null;
        $this->serviceName = $input['ServiceName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceName".'));
        $this->serviceUserName = $input['ServiceUserName'] ?? null;
        $this->servicePassword = $input['ServicePassword'] ?? null;
        $this->serviceCredentialAlias = $input['ServiceCredentialAlias'] ?? null;
        $this->serviceCredentialSecret = $input['ServiceCredentialSecret'] ?? null;
        $this->serviceSpecificCredentialId = $input['ServiceSpecificCredentialId'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceSpecificCredentialId".'));
        $this->userName = $input['UserName'] ?? $this->throwException(new InvalidArgument('Missing required field "UserName".'));
        $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".'));
    }

    /**
     * @param array{
     *   CreateDate: \DateTimeImmutable,
     *   ExpirationDate?: \DateTimeImmutable|null,
     *   ServiceName: string,
     *   ServiceUserName?: string|null,
     *   ServicePassword?: string|null,
     *   ServiceCredentialAlias?: string|null,
     *   ServiceCredentialSecret?: string|null,
     *   ServiceSpecificCredentialId: string,
     *   UserName: string,
     *   Status: StatusType::*,
     * }|ServiceSpecificCredential $input
     */
    public static function create($input): self
    {
        return $input instanceof self ? $input : new self($input);
    }

    public function getCreateDate(): \DateTimeImmutable
    {
        return $this->createDate;
    }

    public function getExpirationDate(): ?\DateTimeImmutable
    {
        return $this->expirationDate;
    }

    public function getServiceCredentialAlias(): ?string
    {
        return $this->serviceCredentialAlias;
    }

    public function getServiceCredentialSecret(): ?string
    {
        return $this->serviceCredentialSecret;
    }

    public function getServiceName(): string
    {
        return $this->serviceName;
    }

    public function getServicePassword(): ?string
    {
        return $this->servicePassword;
    }

    public function getServiceSpecificCredentialId(): string
    {
        return $this->serviceSpecificCredentialId;
    }

    public function getServiceUserName(): ?string
    {
        return $this->serviceUserName;
    }

    /**
     * @return StatusType::*
     */
    public function getStatus(): string
    {
        return $this->status;
    }

    public function getUserName(): string
    {
        return $this->userName;
    }

    /**
     * @return never
     */
    private function throwException(\Throwable $exception)
    {
        throw $exception;
    }
}
