/*-
 * ~~~~~~licensing~~~~~~
 * permission-api
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * 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
 * 
 *      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.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.system.core.permission.jpa.entity;


import com.sun.istack.NotNull;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "permission")
public class Permission {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;
    @NotNull
    @Column(name = "object_id")
    private long objectId;
    @NotNull
    @Column(name = "object_type")
    private String objectType;
    @NotNull
    @Column(name = "subject_id")
    private String subjectId;
    @NotNull
    @Column(name = "subject_type")
    private String subjectType;
    @NotNull
    @Column(name = "action")
    private String action;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getObjectId() {
        return objectId;
    }

    public void setObjectId(long objectId) {
        this.objectId = objectId;
    }

    public String getObjectType() {
        return objectType;
    }

    public void setObjectType(String objectType) {
        this.objectType = objectType;
    }

    public String getSubjectId() {
        return subjectId;
    }

    public void setSubjectId(String subjectId) {
        this.subjectId = subjectId;
    }

    public String getSubjectType() {
        return subjectType;
    }

    public void setSubjectType(String subjectType) {
        this.subjectType = subjectType;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    @Override
    public int hashCode() {
        return Objects.hash(action, id, objectId, objectType, subjectId, subjectType);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Permission other = (Permission) obj;
        return Objects.equals(action, other.action) && id == other.id && objectId == other.objectId
                && Objects.equals(objectType, other.objectType) && Objects.equals(subjectId, other.subjectId)
                && Objects.equals(subjectType, other.subjectType);
    }

    @Override
    public String toString() {
        return "Permission [id=" + id + ", objectId=" + objectId + ", objectType=" + objectType + ", subjectId="
                + subjectId + ", subjectType=" + subjectType + ", action=" + action + "]";
    }


}
