<%#
 Copyright 2013-2024 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed 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

      https://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 <%= packageName %>.service.dto;

<%_ if (!databaseTypeNo) { _%>
import <%= user.entityAbsoluteClass %>;
<%_ } _%>

import java.io.Serializable;
import java.util.Objects;
<%_ if (user.primaryKey.hasUUID) { _%>
import java.util.UUID;
<%_ } _%>

/**
 * A DTO representing a user, with only the public attributes.
 */
public class <%= user.dtoClass %> implements Serializable {
    private static final long serialVersionUID = 1L;

    private <%= user.primaryKey.type %> id;

    private String login;

<%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
    private String <%= field.fieldName %>;
<%_ } _%>

    private String firstName;

    private String imageUrl;

<%_ if (databaseType !== 'no' && false) { _%>
    public <%= user.dtoClass %>() {
        // Empty constructor needed for Jackson.
    }

    public <%= user.dtoClass %>(<%= user.persistClass %> user) {
        this.id = user.getId();
        // Customize it here if you need, or not, firstName/lastName/etc
        this.login = user.getLogin();
  <%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
        this.<%= field.fieldName %> = user.get<%= field.propertyJavaBeanName %>();
  <%_ } _%>
    }

<%_ } _%>
    public <%= user.primaryKey.type %> getId() {
        return id;
    }

    public void setId(<%= user.primaryKey.type %> id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

<%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
    public String get<%= field.propertyJavaBeanName %>() {
        return <%= field.fieldName %>;
    }

    public void set<%= field.propertyJavaBeanName %>(String <%= field.fieldName %>) {
        this.<%= field.fieldName %> = <%= field.fieldName %>;
    }

<%_ } _%>
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        <%= user.dtoClass %> userDTO = (<%= user.dtoClass %>) o;
        if (userDTO.getId() == null || getId() == null) {
            return false;
        }

        return Objects.equals(getId(), userDTO.getId()) &&
<%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
            Objects.equals(get<%= field.propertyJavaBeanName %>(), userDTO.get<%= field.propertyJavaBeanName %>()) &&
<%_ } _%>
            Objects.equals(getLogin(), userDTO.getLogin());
    }

    @Override
    public int hashCode() {
        return Objects.hash(
            getId(),
<%_ for (const { propertyJavaBeanName } of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
          get<%= field.propertyJavaBeanName %>(),
<%_ } _%>
            getLogin()
        );
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "<%= user.dtoClass %>{" +
            "id='" + id + '\'' +
            ", login='" + login + '\'' +
<%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%>
            ", <%= field.fieldName %>='" + <%= field.fieldName %> + '\'' +
<%_ } _%>
            "}";
    }

}
