package com.izouma.dingdong.dto;

import com.izouma.dingdong.annotations.Searchable;
import com.izouma.dingdong.domain.backstage.Category;
import com.izouma.dingdong.domain.backstage.MerchantNature;
import com.izouma.dingdong.domain.merchant.FullReduction;
import com.izouma.dingdong.domain.merchant.Merchant;
import com.izouma.dingdong.domain.merchant.MerchantSettings;
import com.izouma.dingdong.enums.ApplyStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MerchantDTO implements Serializable {
    public MerchantDTO(Merchant merchant, MerchantSettings merchantSettings) {
        address = merchant.getAddress();
        aliAccount = merchant.getAliAccount();
        aliName = merchant.getAliName();
        blacklist = merchant.getBlacklist();
        merchantNatureId = merchantSettings.getMerchantNatureId();
        category = merchantSettings.getCategory();
        enabled = merchant.getEnabled();
        endTime = merchantSettings.getEndTime();
        firstOrder = merchantSettings.getFirstOrder();
        mid = merchant.getId();
        img = merchantSettings.getImg();
        introduction = merchantSettings.getIntroduction();
        name = merchant.getName();
        /*    newUser = merchantSettings.getNewUser();*/
        phone = merchant.getPhone();
        qualification = merchantSettings.getQualification();
        showName = merchant.getShowName();
        startTime = merchantSettings.getStartTime();
        isPass = merchant.getIsPass();
        status = merchant.getStatus();
        establishTime = merchant.getEstablishTime();
        week = merchantSettings.getWeek();
        banner = merchantSettings.getBanner();
        logo = merchant.getLogo();
        proclamation = merchantSettings.getProclamation();
        userId = merchant.getUserId();
        merchantNature = merchantSettings.getMerchantNature();
        startingAmount = merchantSettings.getStartingAmount();
        preparationTime = merchantSettings.getPreparationTime();
        isOpening = merchantSettings.getIsOpening();
        automaticOrder = merchantSettings.getAutomaticOrder();
        doorHeadImg = merchantSettings.getDoorHeadImg();
        promo = merchant.getPromo();
        buyAlliance = merchantSettings.getBuyAlliance();
        monthSales = merchant.getMonthSales();
        goodNum = merchant.getGoodNum();
        badNum = merchant.getBadNum();
        tag = merchant.getTag();
    }

    //包含距离
    public MerchantDTO(Merchant merchant, MerchantSettings merchantSettings, Double distance) {
        address = merchant.getAddress();
        aliAccount = merchant.getAliAccount();
        aliName = merchant.getAliName();
        blacklist = merchant.getBlacklist();
        merchantNatureId = merchantSettings.getMerchantNatureId();
        category = merchantSettings.getCategory();
        enabled = merchant.getEnabled();
        endTime = merchantSettings.getEndTime();
        firstOrder = merchantSettings.getFirstOrder();
        mid = merchant.getId();
        img = merchantSettings.getImg();
        introduction = merchantSettings.getIntroduction();
        name = merchant.getName();
        /*    newUser = merchantSettings.getNewUser();*/
        phone = merchant.getPhone();
        qualification = merchantSettings.getQualification();
        showName = merchant.getShowName();
        startTime = merchantSettings.getStartTime();
        isPass = merchant.getIsPass();
        status = merchant.getStatus();
        establishTime = merchant.getEstablishTime();
        week = merchantSettings.getWeek();
        banner = merchantSettings.getBanner();
        logo = merchant.getLogo();
        proclamation = merchantSettings.getProclamation();
        userId = merchant.getUserId();
        merchantNature = merchantSettings.getMerchantNature();
        startingAmount = merchantSettings.getStartingAmount();
        preparationTime = merchantSettings.getPreparationTime();
        isOpening = merchantSettings.getIsOpening();
        automaticOrder = merchantSettings.getAutomaticOrder();
        doorHeadImg = merchantSettings.getDoorHeadImg();
        promo = merchant.getPromo();
        buyAlliance = merchantSettings.getBuyAlliance();
        monthSales = merchant.getMonthSales();
        this.distance = distance;
        priority = merchantSettings.getPriority();
        goodNum = merchant.getGoodNum();
        badNum = merchant.getBadNum();
        tag = merchant.getTag();
    }

    private Long mid;

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

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

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

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

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

    @ApiModelProperty(value = "密码", name = "password")
    private String password;

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

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

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

    @Column(nullable = false)
    private Boolean enabled;

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

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

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

    @ApiModelProperty(value = "首单优惠", name = "firstOrder")
    private BigDecimal firstOrder;

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

    @BatchSize(size = 20)
    @ApiModelProperty(value = "经营品类", name = "category")
    private Set<Category> category;

    private String categoryId;

/*
    @ApiModelProperty(value = "标签", name = "tag")
    private Set<Tag> tag;*/

    @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;

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

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

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

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

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

    private MerchantNature merchantNature;

//    @ApiModelProperty(value = "首单优惠需求")
//    private String demand;

    @ApiModelProperty(value = "起送金额")
    private BigDecimal startingAmount;

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

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

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

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

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

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

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

    @ApiModelProperty(value = "距离")
    private Double distance;

    @ApiModelProperty(value = "满减")
    private List<FullReduction> fullReductions;

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

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

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

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