package com.izouma.nineth.domain;

import com.izouma.nineth.annotations.Searchable;
import com.izouma.nineth.converter.StringArrayConverter;
import com.izouma.nineth.dto.MessageDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@ApiModel("留言")
public class Message extends BaseEntity {

    @ApiModelProperty("用户ID")
    private Long userId;

    @Searchable
    @ApiModelProperty("昵称")
    private String nickname;

//    @Searchable
//    @ApiModelProperty("手机号")
//    private String phone;

    private String type;

    @ApiModelProperty("详情")
    private String detail;

    @ApiModelProperty("图片")
    @Column(columnDefinition = "TEXT")
    @Convert(converter = StringArrayConverter.class)
    private List<String> pic;

    @ApiModelProperty("是否回复")
    private boolean reply;

    @Column(columnDefinition = "TEXT")
    @ApiModelProperty("回复详情")
    private String replyDetail;

    @ApiModelProperty("图片")
    @Column(columnDefinition = "TEXT")
    @Convert(converter = StringArrayConverter.class)
    private List<String> replyPic;

    @ApiModelProperty("回复时间")
    private LocalDateTime repliedAt;

    private String status;

    public Message(MessageDTO dto) {
        BeanUtils.copyProperties(dto, this);
    }
}
