package com.brframework.webapppatch.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.brframework.commoncms.annatotion.column.SelectColumn;
import com.brframework.commoncms.annatotion.column.TextAreaColumn;
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;

/**
 * @author xu
 * @date 2019/11/14 21:08
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel
@Table(name = "sys_app_version")
public class AppVersion {

    /** 正常更新 */
    public static final Integer UPDATE_TYPE_NORMAL = 1;
    /** 强制更新 */
    public static final Integer UPDATE_TYPE_COERCE = 2;

    /** 已提交 */
    public static final Integer UPDATE_STATUS_SUBMIT = 1;
    /** 灰度发布 */
    public static final Integer UPDATE_STATUS_GRAY = 2;
    /** 正式发布 */
    public static final Integer UPDATE_STATUS_RELEASE = 3;
    /** 版本失败 */
    public static final Integer UPDATE_STATUS_DEFEATED = 4;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "id", required = true, example = "1")
    Long id;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间", required = true, example = "2019-04-24 16:23:19")
    @Column(updatable = false)
    LocalDateTime createDate;

    @ApiModelProperty(value = "版本号",required = true, example = "30")
    private String version;

    @ApiModelProperty(value = "版本名称",required = true, example = "1.1.2")
    private String versionName;

    @ApiModelProperty(value = "操作系统", required = true, example = "Android")
    @SelectColumn(options = {"ANDROID,ANDROID", "IOS,IOS"})
    private String os;

    @ApiModelProperty(value = "新版本信息",required = true, example = "更新了挺多的了")
    @Column(length = 2048)
    @TextAreaColumn
    private String versionMessage;

    @ApiModelProperty(value = "新版本下载地址",required = true, example = "http://wwww.google.com")
    @Column(length = 2048)
    private String versionUrl;

    @ApiModelProperty(value = "文件大小",required = true, example = "1184219")
    private long fileSize;

    @ApiModelProperty(value = "更新类型(1.正常更新 2.强制更新)", example = "1", allowableValues = "1,2")
    @SelectColumn(options = {"1,正常更新", "2,强制更新"})
    private Integer updateType;

    @ApiModelProperty(value = "更新状态(1.已提交 2.灰度测试 3.发布 4.失败)", example = "1", allowableValues = "1,2,3,4")
    @SelectColumn(options = {"1,已提交", "2,灰度测试", "3,发布", "4,失败"})
    private Integer updateStatus;
}
