package com.izouma.zhirongip.domain.resource;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.izouma.zhirongip.annotations.EnumFormat;
import com.izouma.zhirongip.annotations.Searchable;
import com.izouma.zhirongip.domain.BaseEntity;
import com.izouma.zhirongip.domain.Setting;
import com.izouma.zhirongip.enums.CaseCategory;
import com.izouma.zhirongip.enums.LogoType;
import com.izouma.zhirongip.enums.PatentType;
import com.izouma.zhirongip.enums.TechTradingMethod;
import com.izouma.zhirongip.utils.excel.EnumExcelConverter;
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.math.BigDecimal;
import java.time.LocalDate;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Where(clause = "del = 0")
@ApiModel(value = "成功案例")
public class SuccessCase extends BaseEntity {
    @Searchable
    @ApiModelProperty(value = "名称")
    private String name;

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

    /*
    所属领域/商标类型/版权分类/软著分类/服务类型
     */
    @ExcelIgnore
    private Long settingId;

    @ApiModelProperty(value = "成交时间")
    private LocalDate soldAt;

    @ApiModelProperty(value = "成交价格")
    private BigDecimal soldPrice;

    @ExcelProperty(value = "专利类型", converter = EnumExcelConverter.class)
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "转移转化方式")
    private TechTradingMethod mode;

    @ApiModelProperty(value = "成交地点")
    private String soldAddress;

    @Searchable
    @ExcelIgnore
    @Column(columnDefinition = "TEXT")
    @ApiModelProperty(value = "描述")
    private String manual;

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

    /*
    普通专利 ---专利类型
     */
    @EnumFormat(value = PatentType.class,
            fromExcel = {"发明专利", "实用新型专利", "外观设计专利"},
            toJavaEnum = {"INVENTION", "UTILITY_MODEL", "APPEARANCE_DESIGN"})
    @ExcelProperty(value = "专利类型", converter = EnumExcelConverter.class)
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "专利类型")
    private PatentType patentType;

    /*
    商标
     */
    @EnumFormat(value = LogoType.class,
            fromExcel = {"普通商标", "集体商标", "证明商标"},
            toJavaEnum = {"GENERAL", "COLLECTIVE", "PROOF"})
    @ExcelProperty(value = "商标类型", converter = EnumExcelConverter.class)
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "商标类型")
    private LogoType logoType;

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

    @ExcelIgnore
    @Enumerated(EnumType.STRING)
    private CaseCategory category;
}
