package com.sysu.admin.controller.crop.images;


import com.alibaba.fastjson.annotation.JSONField;
import com.sysu.admin.support.system.config.ConfigContext;
import com.xiesx.fastboot.core.jpa.entity.JpaPlusEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Base64;
import java.util.Date;

/**
 * @title 上传记录
 * @description
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@FieldNameConstants(innerTypeName = "FIELDS")
@Table(name = "p_crop_image")
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
public class CropImage extends JpaPlusEntity<CropImage> {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private Long cropId;

    @Column
    private String filename;

    /**
     * 类型 是远景0还是中景1 还是近景色2
     */
    @Column
    private Integer type;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(updatable = false, nullable = false)
    private Date createDate;

    /**
     * 纬度
     */
    @Column
    private String latitude;

    /**
     * 经度
     */
    @Column
    private String longitude;

    @Column
    private String alpha;

    @Column
    private String beta;

    @Column
    private String gamma;

    public String getUrl(){
        return ConfigContext.imageBase + this.filename;
    }

    @Transient
    private String base64;

    @JSONField(serialize = false)
    public static ImageType getImageType(int val){
        switch (val){
            case 0:
                return ImageType.fay;
            case 1:
                return ImageType.center;
            case 2:
                return ImageType.near;
        }
        return null;
    }
}
