package com.izouma.dingdong.domain.merchant;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.izouma.dingdong.annotations.Searchable;
import com.izouma.dingdong.domain.BaseEntity;
import com.izouma.dingdong.domain.User;
import com.izouma.dingdong.enums.ApplyStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(value = {"hibernateLazyInitializer"})
@Where(clause = "enabled = 1")
@ApiModel(value = "商户信息", description = "商户信息")
public class Merchant extends BaseEntity implements Serializable {

    @ApiModelProperty(value = "用户ID", name = "userId")
    private Long userId;

    @Searchable
    @ApiModelProperty(value = "商户名称", name = "name")
    private String name;

    @Searchable
    @ApiModelProperty(value = "显示名称", name = "showName")
    private String showName;

    @Searchable
    @ApiModelProperty(value = "商户电话", name = "phone")
    private String phone;

    @ApiModelProperty(value = "logo", name = "logo")
    private String logo;

    @ApiModelProperty(value = "商户地址", name = "address")
    private String address;

    @Builder.Default
    @Column(nullable = false)
    @ApiModelProperty(value = "黑名单", name = "blacklist")
    private Boolean blacklist = false;

    @Column(nullable = false)
    private Boolean enabled = true;

    @Searchable
    @ApiModelProperty(value = "支付宝名称", name = "aliName")
    private String aliName;

    @Searchable
    @ApiModelProperty(value = "支付宝账号", name = "aliAccount")
    private String aliAccount;

    @ApiModelProperty(value = "总好评数量", name = "goodNum")
    private Integer goodNum;

    @ApiModelProperty(value = "差评数量", name = "badNum")
    private Integer badNum;

    @ApiModelProperty(value = "月销", name = "monthSales")
    private Integer monthSales;

    @ApiModelProperty(value = "通过", name = "isPass")
    private Boolean isPass;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "状态", name = "status")
    private ApplyStatus status;

    @ApiModelProperty(value = "成立时间", name = "established")
    private LocalDateTime establishTime;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.DETACH)
    @JoinColumn(name = "userId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private User user;

    @ApiModelProperty(value = "经度", name = "longitude")
    private Double longitude;

    @ApiModelProperty(value = "纬度", name = "latitude")
    private Double latitude;

    @Size(max = 15)
    @Column(length = 15)
    @ApiModelProperty(value = "推广语", name = "promo")
    private String promo;

    /**
     * 都不是 0
     * 新商家 1
     * 明星商家 2
     */
    @ApiModelProperty(value = "商家标签", name = "tag")
    private Integer tag;
}