package com.izouma.dingdong.domain.merchant;

import com.izouma.dingdong.domain.BaseEntity;
import com.izouma.dingdong.domain.backstage.Category;
import com.izouma.dingdong.domain.backstage.MerchantNature;
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.BatchSize;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.Set;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
@ApiModel(value = "商户设置", description = "商户设置")
public class MerchantSettings extends BaseEntity implements Serializable {
/*    @ApiModelProperty(value = "用户ID")
    private Long userId;*/

    @ApiModelProperty(value = "商户ID", name = "merchantId")
    private Long merchantId;

    @ApiModelProperty(value = "图片", name = "img")
    private String img;

    @ApiModelProperty(value = "横幅", name = "banner")
    private String banner;

    @ApiModelProperty(value = "公告", name = "proclamation")
    private String proclamation;

    @ApiModelProperty(value = "简介", name = "introduction")
    private String introduction;

    @Column(precision = 10, scale = 2)
    @ApiModelProperty(value = "首单优惠", name = "firstOrder")
    private BigDecimal firstOrder;

/*
    @Column(precision = 10, scale = 2)
    @ApiModelProperty(value = "新用户优惠", name = "newUser")
    private BigDecimal newUser;
*/

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH})
    @JoinTable(
            name = "merchant_cate",
            joinColumns = {@JoinColumn(name = "mer_id", referencedColumnName = "id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))},
            inverseJoinColumns = {@JoinColumn(name = "cate_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))})
    @BatchSize(size = 20)
    @ApiModelProperty(value = "经营品类", name = "category")
    private Set<Category> category = new HashSet<>();

    @ApiModelProperty(value = "周几", name = "week")
    private String week;

    @ApiModelProperty(value = "营业时间", name = "startTime")
    private LocalTime startTime;

    @ApiModelProperty(value = "营业时间", name = "endTime")
    private LocalTime endTime;

    @ApiModelProperty(value = "营业资质图片", name = "qualification")
    private String qualification;

    @ApiModelProperty(value = "商家性质", name = "merchantNatureId")
    private Long merchantNatureId;

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

    @ApiModelProperty(value = "自动接单", name = "automaticOrder")
    private Boolean automaticOrder = false;

    @ApiModelProperty(value = "是否营业中", name = "isOpening")
    private Boolean isOpening;

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

    @Column(precision = 10, scale = 2)
    @ApiModelProperty(value = "起送金额", name = "startingAmount")
    private BigDecimal startingAmount;

    /**
     * 每餐准备时间
     */
    @ApiModelProperty(value = "每餐准备时间", name = "preparationTime")
    private Long preparationTime;

    @ApiModelProperty(value = "门头图片", name = "doorHeadImg")
    private String doorHeadImg;

    @ApiModelProperty(value = "购买口碑联盟", name = "buyAlliance")
    private Boolean buyAlliance;

    @ApiModelProperty(value = "优先级", name = "priority")
    private Integer priority;

}
