package com.bytesw.bytebot.model;

import com.bytesw.bytebot.model.converters.AgentStatusConverter;
import com.bytesw.bytebot.model.converters.AgentTypeConverter;
import com.bytesw.bytebot.model.converters.LanguageConverter;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import com.bytesw.bytebot.model.enums.LanguageEnum;
import lombok.*;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Audited
@Entity
@Getter @Setter @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "avb_agent")
@NamedQuery(name = "Agent.findByPK", query = "Select u from Agent u where u.id = ?1")
public class Agent implements Serializable {

    @Id
    @Column(name = "agen_id")
    @SequenceGenerator(name = "AVB_AGENT_GENERATOR", sequenceName = "AVB_AGENT_SEQ", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AVB_AGENT_GENERATOR")
    private Long id;

    @Column(name = "agen_iden")
    private String name;

    @Column(name = "agen_descr")
    private String description;

    @Column(name = "agen_vers")
    private String version;

    @Column(name = "agen_lang")
    @Convert(converter =  LanguageConverter.class)
    private LanguageEnum language;

    @Column(name = "agen_tzone")
    private String timezone;

    @Column(name = "agen_delete_sensible_period")
    private int period;

    @Lob
    @Type(type = "org.hibernate.type.TextType")
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "agen_avat")
    private String avatar;

    @ManyToOne
    @JoinColumn(name = "coun_id", referencedColumnName = "coun_id")
    private Country country;

    @Column(name = "agen_state")
    @Convert(converter =  AgentStatusConverter.class)
    private AgentStatusEnum status;

    @Column(name = "agen_type")
    @Convert(converter =  AgentTypeConverter.class)
    private AgentTypeEnum type;

    @OneToMany(mappedBy = "agent")
    private List<DeploymentChannel> deploymentChannels;

    @OneToMany(mappedBy = "agent")
    private List<FrequentQuestion> frequentQuestions;

}
