package com.example.demo.news.model;

import java.util.Objects;

import com.example.demo.core.model.BaseEntity;
import com.example.demo.department.model.DepartmentEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "news")
public class NewsEntity extends BaseEntity {
    @Column(nullable = false, unique = false, length = 10)
    private String date;
    @Column(nullable = false, unique = false, length = 15)
    private String name;
    @Column(nullable = false, unique = false, length = 80)
    private String description;
    @ManyToOne
    @JoinColumn(name = "departmentId", nullable = false)
    private DepartmentEntity department;

    public NewsEntity() {
    }

    public NewsEntity(String date, String name, String description, DepartmentEntity department) {
        this.date = date;
        this.name = name;
        this.description = description;
        this.department = department;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DepartmentEntity getDepartment() {
        return department;
    }

    public void setDepartment(DepartmentEntity department) {
        this.department = department;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        final NewsEntity other = (NewsEntity) obj;
        return Objects.equals(other.getId(), id)
                && Objects.equals(other.getDate(), date)
                && Objects.equals(other.getName(), name)
                && Objects.equals(other.getDescription(), description);
    }
}
