package com.izouma.jmrh.domain;

import com.izouma.jmrh.annotations.Searchable;
import com.izouma.jmrh.converter.FileObjectListConverter;
import com.izouma.jmrh.converter.StringArrayConverter;
import com.izouma.jmrh.enums.AuditStatus;
import com.izouma.jmrh.enums.ConversationStatus;
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;
import java.util.List;

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("资源供需")
public class ResourceSupplyAndDemand extends BaseEntity {
    @Searchable
    @ApiModelProperty("名称")
    private String name;

    @ApiModelProperty("发布企业")
    private Long orgId;

    @ApiModelProperty("发布人")
    private Long publishersId;

    @ApiModelProperty("有效期")
    private LocalDateTime expireTime;

    @ApiModelProperty("联系人")
    private String contact;

    @ApiModelProperty("联系方式")
    private String phone;

    @ApiModelProperty("联系地址")
    private String address;

    @ApiModelProperty("审核状态")
    @Enumerated(EnumType.STRING)
    private AuditStatus status;

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

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

    @ApiModelProperty("功能简介")
    private String description;

    @ApiModelProperty("详细介绍")
    @Column(columnDefinition = "TEXT")
    private String details;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "resSnDId", insertable = true, updatable = true)
    private List<ResSnDProperty> resSnDPropertyList;

    @ApiModelProperty("对接数量")
    @Transient
    private Integer count;

    @ApiModelProperty("对接状态")
    @Transient
    private ConversationStatus conversationStatus;

    @ApiModelProperty("审核时间")
    private LocalDateTime auditTime;

    //添加附件的功能
    @ApiModelProperty("附件")
    @Convert(converter = FileObjectListConverter.class)
    @Column(columnDefinition = "TEXT")
    private List<FileObject> attachment;
}
