package de.accso.flexinale.data.model;

import de.accso.flexinale.shared_kernel.Identifiable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;

@jakarta.persistence.Entity
public class Film implements Identifiable, Serializable {
    @jakarta.persistence.Id
    public String id;  // primary key

    @jakarta.persistence.Column
    public String titel;

    @jakarta.persistence.Column
    public String imdbUrl;

    @jakarta.persistence.Column
    public Integer dauerInMinuten;

    protected Film() {
    }

    public Film(String id) {
        this.id = id;
    }

    public Film(String id, String titel, String imdbUrl, Integer dauerInMinuten) {
        this.id = id;
        this.titel = titel;
        this.imdbUrl = imdbUrl;
        this.dauerInMinuten = dauerInMinuten;
    }

    @Override
    public Id id() {
        return Identifiable.Id.of(id);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {return true;}

        if (o == null || getClass() != o.getClass()) {return false;}

        Film that = (Film) o;

        return new EqualsBuilder()
                .append(id, that.id)
                .append(titel, that.titel)
                .append(imdbUrl, that.imdbUrl)
                .append(dauerInMinuten, that.dauerInMinuten)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(id).append(titel).append(imdbUrl).append(dauerInMinuten).toHashCode();
    }
}
