001package ca.cdr.api.model.json;
002
003/*-
004 * #%L
005 * Smile CDR - CDR
006 * %%
007 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
008 * %%
009 * All rights reserved.
010 * #L%
011 */
012
013import com.fasterxml.jackson.annotation.JsonProperty;
014import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
015import com.fasterxml.jackson.databind.annotation.JsonSerialize;
016import io.swagger.v3.oas.annotations.media.Schema;
017import jakarta.validation.constraints.NotBlank;
018import org.apache.commons.lang3.builder.EqualsBuilder;
019import org.apache.commons.lang3.builder.HashCodeBuilder;
020import org.apache.commons.lang3.builder.ToStringBuilder;
021import org.apache.commons.lang3.builder.ToStringStyle;
022
023import java.io.Serializable;
024import java.util.Date;
025
026@Schema(name = "OAuth2ClientSecret", description = "A client secret for an OAuth2 client")
027public class OAuth2ClientSecretJson implements Serializable, IModelJson {
028
029        @JsonProperty("pid")
030        private Long myPid;
031
032        @NotBlank
033        @JsonProperty("secret")
034        private String mySecret;
035
036        @JsonProperty("description")
037        private String myDescription;
038
039        @JsonProperty("expiration")
040        @JsonSerialize(using = JsonDateSerializer.class)
041        @JsonDeserialize(using = JsonDateDeserializer.class)
042        private Date myExpiration;
043
044        @JsonProperty("activation")
045        @JsonSerialize(using = JsonDateSerializer.class)
046        @JsonDeserialize(using = JsonDateDeserializer.class)
047        private Date myActivation;
048
049        /**
050         * Constructor
051         */
052        public OAuth2ClientSecretJson() {
053                super();
054        }
055
056        public String getDescription() {
057                return myDescription;
058        }
059
060        public OAuth2ClientSecretJson setDescription(String theDescription) {
061                myDescription = theDescription;
062                return this;
063        }
064
065        public Long getPid() {
066                return myPid;
067        }
068
069        public void setPid(Long thePid) {
070                myPid = thePid;
071        }
072
073        public Date getActivation() {
074                return myActivation;
075        }
076
077        public OAuth2ClientSecretJson setActivation(Date theActivation) {
078                myActivation = theActivation;
079                return this;
080        }
081
082        @Override
083        public String toString() {
084                return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
085                                .append("secret", mySecret)
086                                .append("activation", myActivation)
087                                .append("expiration", myExpiration)
088                                .toString();
089        }
090
091        @Override
092        public boolean equals(Object theO) {
093                if (this == theO) {
094                        return true;
095                }
096
097                if (theO == null || getClass() != theO.getClass()) {
098                        return false;
099                }
100
101                OAuth2ClientSecretJson that = (OAuth2ClientSecretJson) theO;
102
103                return new EqualsBuilder()
104                                .append(mySecret, that.mySecret)
105                                .append(myActivation, that.myActivation)
106                                .append(myExpiration, that.myExpiration)
107                                .isEquals();
108        }
109
110        @Override
111        public int hashCode() {
112                return new HashCodeBuilder(17, 37)
113                                .append(mySecret)
114                                .append(myActivation)
115                                .append(myExpiration)
116                                .toHashCode();
117        }
118
119        public String getSecret() {
120                return mySecret;
121        }
122
123        public OAuth2ClientSecretJson setSecret(String theSecret) {
124                mySecret = theSecret;
125                return this;
126        }
127
128        public Date getExpiration() {
129                return myExpiration;
130        }
131
132        public OAuth2ClientSecretJson setExpiration(Date theExpiration) {
133                if (theExpiration != null && theExpiration.getClass().equals(Date.class) == false) {
134                        // java.sql.Date is a subclass of Date, but equals() comparisons don't work well
135                        // and it doesn't add any value, so switch these back to normal dates..
136                        myExpiration = new Date(theExpiration.getTime());
137                } else {
138                        myExpiration = theExpiration;
139                }
140                return this;
141        }
142}