package com.izouma.zhirongip.domain.resource;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.izouma.zhirongip.annotations.Searchable;
import com.izouma.zhirongip.annotations.SearchableOne;
import com.izouma.zhirongip.converter.FileObjectListConverter;
import com.izouma.zhirongip.domain.BaseEntity;
import com.izouma.zhirongip.domain.FileObject;
import com.izouma.zhirongip.domain.Setting;
import com.izouma.zhirongip.enums.ResourceCategory;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@ApiModel(value = "政策法律")
@Where(clause = "del = 0")
public class PolicyLaw extends BaseEntity {
    @Searchable
    @SearchableOne
    @ApiModelProperty(value = "名称")
    private String name;

    /*
    setting 政策-7 新闻-8 法律-9
     */
    @ExcelIgnore
    @ApiModelProperty(value = "类型")
    private Long typeSettingId;

    @ApiModelProperty(value = "发文时间")
    private LocalDate issuedAt;

    @SearchableOne
    @ApiModelProperty(value = "发文单位")
    private String issuedBy;

    /*
    只有政策有
     */
    @SearchableOne
    @ApiModelProperty(value = "发文号")
    private String issuedCode;

    @ApiModelProperty(value = "封面图片")
    private String img;

    @Searchable
    @ExcelIgnore
    @ApiModelProperty(value = "内容")
    @Column(columnDefinition = "TEXT")
    private String content;

    @Column(columnDefinition = "TEXT")
    @ApiModelProperty(value = "摘要")
    private String summary;

    /*
    只有法律有
     */
    @ApiModelProperty(value = "实施年份")
    private LocalDate implementationAt;

    @ExcelIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "typeSettingId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @NotFound(action = NotFoundAction.IGNORE)
    private Setting setting;

    @Enumerated(EnumType.STRING)
    private ResourceCategory category;

    @Column(columnDefinition = "TEXT ")
    @Convert(converter = FileObjectListConverter.class)
    private List<FileObject> annex;

//    @ApiModelProperty(value = "浏览量")
//    private long view;
}
