/*
 * Copyright (c) 2023-2025, WSO2 LLC. (http://www.wso2.com).
 *
 * WSO2 LLC. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.carbon.identity.api.server.application.management.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.*;


import io.swagger.annotations.*;
import java.util.Objects;
import javax.validation.Valid;
import javax.xml.bind.annotation.*;

public class RefreshTokenConfiguration  {
  
    private Long expiryInSeconds;
    private Boolean extendRenewedRefreshTokenExpiryTime;
    private Boolean renewRefreshToken;
    private Boolean gracefulRefreshTokenRotationEnabled;
    private Integer gracefulRefreshTokenRotationValidityPeriod;
    private Integer gracefulRefreshTokenReuseLimit;

    /**
    **/
    public RefreshTokenConfiguration expiryInSeconds(Long expiryInSeconds) {

        this.expiryInSeconds = expiryInSeconds;
        return this;
    }
    
    @ApiModelProperty(example = "86400", value = "")
    @JsonProperty("expiryInSeconds")
    @Valid
    public Long getExpiryInSeconds() {
        return expiryInSeconds;
    }
    public void setExpiryInSeconds(Long expiryInSeconds) {
        this.expiryInSeconds = expiryInSeconds;
    }

    /**
    * Decides whether the expiry time of the renewed refresh token needs to be extended based on the refresh token expiry time configured.
    **/
    public RefreshTokenConfiguration extendRenewedRefreshTokenExpiryTime(Boolean extendRenewedRefreshTokenExpiryTime) {

        this.extendRenewedRefreshTokenExpiryTime = extendRenewedRefreshTokenExpiryTime;
        return this;
    }
    
    @ApiModelProperty(example = "false", value = "Decides whether the expiry time of the renewed refresh token needs to be extended based on the refresh token expiry time configured.")
    @JsonProperty("extendRenewedRefreshTokenExpiryTime")
    @Valid
    public Boolean getExtendRenewedRefreshTokenExpiryTime() {
        return extendRenewedRefreshTokenExpiryTime;
    }
    public void setExtendRenewedRefreshTokenExpiryTime(Boolean extendRenewedRefreshTokenExpiryTime) {
        this.extendRenewedRefreshTokenExpiryTime = extendRenewedRefreshTokenExpiryTime;
    }

    /**
    * Decides whether the refresh token needs to be renewed during refresh grant flow.
    **/
    public RefreshTokenConfiguration renewRefreshToken(Boolean renewRefreshToken) {

        this.renewRefreshToken = renewRefreshToken;
        return this;
    }
    
    @ApiModelProperty(example = "true", value = "Decides whether the refresh token needs to be renewed during refresh grant flow.")
    @JsonProperty("renewRefreshToken")
    @Valid
    public Boolean getRenewRefreshToken() {
        return renewRefreshToken;
    }
    public void setRenewRefreshToken(Boolean renewRefreshToken) {
        this.renewRefreshToken = renewRefreshToken;
    }

    /**
    * If enabled, the previous refresh token remains usable for a grace period after rotation instead of being revoked immediately.
    **/
    public RefreshTokenConfiguration gracefulRefreshTokenRotationEnabled(Boolean gracefulRefreshTokenRotationEnabled) {

        this.gracefulRefreshTokenRotationEnabled = gracefulRefreshTokenRotationEnabled;
        return this;
    }
    
    @ApiModelProperty(example = "false", value = "If enabled, the previous refresh token remains usable for a grace period after rotation instead of being revoked immediately.")
    @JsonProperty("gracefulRefreshTokenRotationEnabled")
    @Valid
    public Boolean getGracefulRefreshTokenRotationEnabled() {
        return gracefulRefreshTokenRotationEnabled;
    }
    public void setGracefulRefreshTokenRotationEnabled(Boolean gracefulRefreshTokenRotationEnabled) {
        this.gracefulRefreshTokenRotationEnabled = gracefulRefreshTokenRotationEnabled;
    }

    /**
    * Grace window (in seconds) during which the previous refresh token remains usable after rotation. Only meaningful when gracefulRefreshTokenRotationEnabled is true.
    **/
    public RefreshTokenConfiguration gracefulRefreshTokenRotationValidityPeriod(Integer gracefulRefreshTokenRotationValidityPeriod) {

        this.gracefulRefreshTokenRotationValidityPeriod = gracefulRefreshTokenRotationValidityPeriod;
        return this;
    }
    
    @ApiModelProperty(example = "60", value = "Grace window (in seconds) during which the previous refresh token remains usable after rotation. Only meaningful when gracefulRefreshTokenRotationEnabled is true.")
    @JsonProperty("gracefulRefreshTokenRotationValidityPeriod")
    @Valid
    public Integer getGracefulRefreshTokenRotationValidityPeriod() {
        return gracefulRefreshTokenRotationValidityPeriod;
    }
    public void setGracefulRefreshTokenRotationValidityPeriod(Integer gracefulRefreshTokenRotationValidityPeriod) {
        this.gracefulRefreshTokenRotationValidityPeriod = gracefulRefreshTokenRotationValidityPeriod;
    }

    /**
    * Maximum number of times the previous refresh token may be reused during the grace window. Only meaningful when gracefulRefreshTokenRotationEnabled is true.
    **/
    public RefreshTokenConfiguration gracefulRefreshTokenReuseLimit(Integer gracefulRefreshTokenReuseLimit) {

        this.gracefulRefreshTokenReuseLimit = gracefulRefreshTokenReuseLimit;
        return this;
    }
    
    @ApiModelProperty(example = "1", value = "Maximum number of times the previous refresh token may be reused during the grace window. Only meaningful when gracefulRefreshTokenRotationEnabled is true.")
    @JsonProperty("gracefulRefreshTokenReuseLimit")
    @Valid
    public Integer getGracefulRefreshTokenReuseLimit() {
        return gracefulRefreshTokenReuseLimit;
    }
    public void setGracefulRefreshTokenReuseLimit(Integer gracefulRefreshTokenReuseLimit) {
        this.gracefulRefreshTokenReuseLimit = gracefulRefreshTokenReuseLimit;
    }



    @Override
    public boolean equals(java.lang.Object o) {

        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RefreshTokenConfiguration refreshTokenConfiguration = (RefreshTokenConfiguration) o;
        return Objects.equals(this.expiryInSeconds, refreshTokenConfiguration.expiryInSeconds) &&
            Objects.equals(this.extendRenewedRefreshTokenExpiryTime, refreshTokenConfiguration.extendRenewedRefreshTokenExpiryTime) &&
            Objects.equals(this.renewRefreshToken, refreshTokenConfiguration.renewRefreshToken) &&
            Objects.equals(this.gracefulRefreshTokenRotationEnabled, refreshTokenConfiguration.gracefulRefreshTokenRotationEnabled) &&
            Objects.equals(this.gracefulRefreshTokenRotationValidityPeriod, refreshTokenConfiguration.gracefulRefreshTokenRotationValidityPeriod) &&
            Objects.equals(this.gracefulRefreshTokenReuseLimit, refreshTokenConfiguration.gracefulRefreshTokenReuseLimit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(expiryInSeconds, extendRenewedRefreshTokenExpiryTime, renewRefreshToken, gracefulRefreshTokenRotationEnabled, gracefulRefreshTokenRotationValidityPeriod, gracefulRefreshTokenReuseLimit);
    }

    @Override
    public String toString() {

        StringBuilder sb = new StringBuilder();
        sb.append("class RefreshTokenConfiguration {\n");
        
        sb.append("    expiryInSeconds: ").append(toIndentedString(expiryInSeconds)).append("\n");
        sb.append("    extendRenewedRefreshTokenExpiryTime: ").append(toIndentedString(extendRenewedRefreshTokenExpiryTime)).append("\n");
        sb.append("    renewRefreshToken: ").append(toIndentedString(renewRefreshToken)).append("\n");
        sb.append("    gracefulRefreshTokenRotationEnabled: ").append(toIndentedString(gracefulRefreshTokenRotationEnabled)).append("\n");
        sb.append("    gracefulRefreshTokenRotationValidityPeriod: ").append(toIndentedString(gracefulRefreshTokenRotationValidityPeriod)).append("\n");
        sb.append("    gracefulRefreshTokenReuseLimit: ").append(toIndentedString(gracefulRefreshTokenReuseLimit)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
    * Convert the given object to string with each line indented by 4 spaces
    * (except the first line).
    */
    private String toIndentedString(java.lang.Object o) {

        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n");
    }
}

