package com.petshop.backend.entity;

import com.petshop.backend.util.PhoneUtils;
import jakarta.persistence.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.Objects;

@Entity
@Table(name = "supplier")
public class Supplier {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long supId;

    @Column(nullable = false, length = 100)
    private String supCompany;

    @Column(nullable = false, length = 50)
    private String supContactFirstName;

    @Column(nullable = false, length = 50)
    private String supContactLastName;

    @Column(nullable = false, length = 100)
    private String supEmail;

    @Column(nullable = false, length = 20)
    private String supPhone;

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    public Supplier() {
    }

    public Supplier(Long supId, String supCompany, String supContactFirstName, String supContactLastName, String supEmail, String supPhone, LocalDateTime createdAt, LocalDateTime updatedAt) {
        this.supId = supId;
        this.supCompany = supCompany;
        this.supContactFirstName = supContactFirstName;
        this.supContactLastName = supContactLastName;
        this.supEmail = supEmail;
        this.supPhone = supPhone;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
    }

    public Long getSupId() {
        return supId;
    }

    public void setSupId(Long supId) {
        this.supId = supId;
    }

    public String getSupCompany() {
        return supCompany;
    }

    public void setSupCompany(String supCompany) {
        this.supCompany = supCompany;
    }

    public String getSupContactFirstName() {
        return supContactFirstName;
    }

    public void setSupContactFirstName(String supContactFirstName) {
        this.supContactFirstName = supContactFirstName;
    }

    public String getSupContactLastName() {
        return supContactLastName;
    }

    public void setSupContactLastName(String supContactLastName) {
        this.supContactLastName = supContactLastName;
    }

    public String getSupEmail() {
        return supEmail;
    }

    public void setSupEmail(String supEmail) {
        this.supEmail = supEmail;
    }

    public String getSupPhone() {
        return supPhone;
    }

    public void setSupPhone(String supPhone) {
        this.supPhone = PhoneUtils.normalize(supPhone);
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Supplier supplier = (Supplier) o;
        return Objects.equals(supId, supplier.supId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(supId);
    }

    @Override
    public String toString() {
        return "Supplier{" +
                "supId=" + supId +
                ", supCompany='" + supCompany + '\'' +
                ", supContactFirstName='" + supContactFirstName + '\'' +
                ", supContactLastName='" + supContactLastName + '\'' +
                ", supEmail='" + supEmail + '\'' +
                ", supPhone='" + supPhone + '\'' +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                '}';
    }
}
