package com.izouma.jmrh.domain;

import com.izouma.jmrh.converter.ContactConverter;
import com.izouma.jmrh.enums.ConversationType;
import com.izouma.jmrh.enums.DockingRole;
import com.izouma.jmrh.enums.ResSnDType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;

@Data
@Entity
@Table(indexes = {@Index(columnList = "sessionId")}, uniqueConstraints = @UniqueConstraint(columnNames = {"userId", "sessionId"}))
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("对话")
public class Conversation extends BaseEntity {
    @Column(length = 96)
    private String sessionId;

    private Long userId;

    private Long toUserId;

    private Long orgId;

    @Column(columnDefinition = "TEXT")
    @Convert(converter = ContactConverter.class)
    private Contact contact;

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "orgId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
//    @NotFound(action = NotFoundAction.IGNORE)
//    private OrgInfo orgInfo;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty("对话类型")
    private ConversationType type;

    private LocalDateTime lastUpdate;

    private String lastMessage;

    @ApiModelProperty("资源id")
    private Long sndId;

    @ApiModelProperty("资源供需类型")
    @Enumerated(EnumType.STRING)
    private ResSnDType resSndType;
}
