package com.izouma.zhirongip.domain.resource;

import cn.hutool.core.bean.BeanUtil;
import com.izouma.zhirongip.annotations.Searchable;
import com.izouma.zhirongip.annotations.SearchableOne;
import com.izouma.zhirongip.converter.StringArrayConverter;
import com.izouma.zhirongip.domain.BaseEntity;
import com.izouma.zhirongip.domain.Setting;
import com.izouma.zhirongip.dto.IntellectualPropertyDTO;
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 IntellectualProperty extends BaseEntity {

//    @ApiModelProperty(value = "发明名称")
//    private String proName;

    @ApiModelProperty(value = "专利代理机构")
    private String agency;

    @ApiModelProperty(value = "代理人")
    private String agent;

    @ApiModelProperty(value = "申请主体")
    private String applyMain;

    @ApiModelProperty(value = "申请人")
    private String applyName;

    @ApiModelProperty(value = "申请日")
    private LocalDate applyTime;

    @ApiModelProperty(value = "授权公告日")
    private LocalDate authTime;

    @ApiModelProperty(value = "公开号")
    private String openCode;

    @SearchableOne
    @ApiModelProperty(value = "申请号")
    private String code;

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

    @ApiModelProperty(value = "发布时间")
    private LocalDate issue;

    @ApiModelProperty(value = "发明人")
    @Convert(converter = StringArrayConverter.class)
    private List<String> inventor;

    @ApiModelProperty(value = "IPC分类")
    @Convert(converter = StringArrayConverter.class)
    private List<String> ipc;

    @SearchableOne
    @Searchable
    @ApiModelProperty(value = "专利权人")
    private String owner;

    @ApiModelProperty(value = "专利权人地址")
    private String ownerOneAddr;

//    @ApiModelProperty(value = "专业领域")
//    private String profession;

    @ApiModelProperty(value = "技术分类1")
    private String techOne;

    private String wordUrl;

    private String pdfUrl;

    @SearchableOne
    @Searchable
    @ApiModelProperty(value = "专利名称")
    private String name;

    /**
     * setting
     */
    @ApiModelProperty(value = "行业分类")
    private Long industryClass;

    //    @EnumFormat(value = IntePropLawStatus.class,
//            fromExcel = {"有效", "失效", "未知"},
//            toJavaEnum = {"EFFECTIVE", "FAILURE", "UNKNOWN"})
//    @ExcelProperty(value = "法律状态", converter = EnumExcelConverter.class)
//    @Enumerated(EnumType.STRING)
    @Transient
    @ApiModelProperty(value = "法律状态")
    private String lawStatus;

    private Long lawStatusId;

    /**
     * 专利区分：包括脱密国防专利，军转民专利
     */
//    @EnumFormat(value = IntePropertyType.class,
//            fromExcel = {"脱密国防专利", "军转民专利"},
//            toJavaEnum = {"DECLASSIFICATION", "MILITARY_TO_CIVILIAN"})
//    @ExcelProperty(value = "专利区分", converter = EnumExcelConverter.class)
//    @Enumerated(EnumType.STRING)
    @Transient
    private String type;

    private Long typeId;

    private String img;

    @Searchable
    @Column(columnDefinition = "TEXT")
    @ApiModelProperty(value = "权利要求书")
    private String manual;


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


    public IntellectualProperty(IntellectualPropertyDTO dto) {
        BeanUtil.copyProperties(dto, this);
    }
}
