package com.iformall.domain.po;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.iformall.common.SortColumn;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.domain.vo.WxShopVo;
import com.iformall.enums.EnumBusiness;
import com.iformall.enums.EnumSubBusiness;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@TableName(value = "wx_merchant")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class WxMerchant extends BaseEntity {

    protected Long id;

    @TableField(exist = false)
	private List<Long> userids;

	@TableField(exist = false)
	private List<Long> shopids;

	@TableField(exist = false)
	private List<WxShop> shops;

	@TableField(exist = false)
	private List<WxShopVo> shopVos;

	@TableField(exist = false)
    private List<WxMerchantBUser> users;

	@TableField(exist = false)
	private Long rentContractId;


	@io.swagger.annotations.ApiModelProperty(value="商户名",name="name")
	@Excel(name="商户名",width = 20,orderNum = "1")
	private String name;

	@io.swagger.annotations.ApiModelProperty(value="联系人",name="linkPerson")
	@Excel(name="联系人",width = 20,orderNum = "2")
	private String linkPerson;

	@io.swagger.annotations.ApiModelProperty(value="联系方式",name="linkPhone")
	@Excel(name="联系方式",width = 20,orderNum = "3")
	private String linkPhone;

	@TableField(exist = false)
	@Excel(name="租期开始时间",width = 20,format="yyyy-MM-dd",orderNum = "4")
    @io.swagger.annotations.ApiModelProperty(value="租期开始时间",name="rentalStartDate")
	private Date rentalStartDate;

	@TableField(exist = false)
	@Excel(name="租期结束时间",width = 20,format="yyyy-MM-dd",orderNum = "5")
    @io.swagger.annotations.ApiModelProperty(value="租期结束时间",name="rentalEndDate")
	private Date rentalEndDate;

	@Excel(name="商户状态",width = 20,orderNum = "6",replace = {"停用_0","正常_1"})
	@io.swagger.annotations.ApiModelProperty(value="状态1可用0停用",name="status")
	private Integer status;

	@TableField(exist = false)
	@Excel(name="账户类型",width = 20,orderNum = "7",replace = {"_null","商户号_0","微信号_1"})
	@io.swagger.annotations.ApiModelProperty(value="账户类型",name="accountTypeValue")
	private Integer accountTypeValue;

	@TableField(exist = false)
	@Excel(name="账户号",width = 20,orderNum = "8")
	@io.swagger.annotations.ApiModelProperty(value="账户ID",name="accountId")
	private String accountId;

	@TableField(exist = false)
	@Excel(name="账户名",width = 20,orderNum = "9")
	@io.swagger.annotations.ApiModelProperty(value="账户名",name="accountName")
	private String accountName;

	@Excel(name="创建时间",width = 20,format="yyyy-MM-dd",orderNum = "10")
	@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
	private Date createDate;

	@Excel(name="是否展示",width = 20,orderNum = "11",replace = {"否_0","是_1"})
	@io.swagger.annotations.ApiModelProperty(value = "是否显示在C端", name = "isPublic")
	private Integer isPublic;

	@Excel(name = "待缴提醒", width = 20, orderNum = "12")
	@io.swagger.annotations.ApiModelProperty(value = "待缴提醒", name = "billSetting")
	private Integer billSetting;

	@TableField(exist = false)
	@Excel(name = "业态", width = 20, orderNum = "13")
	@io.swagger.annotations.ApiModelProperty(value="经营业态ID:参照wx_business表",name="businessId")
	private String businessName;

	@TableField(exist = false)
	@Excel(name = "子业态", width = 20, orderNum = "14")
	@io.swagger.annotations.ApiModelProperty(value="子业态",name="subBusinessId")
	private String subBusinessName;

	@TableField(exist = false)
	@Excel(name = "商铺", width = 20, orderNum = "15")
	private String shopsStr;

	@TableField(exist = false)
	@Excel(name = "管理员", width = 20, orderNum = "16")
	private String usersStr;

	@Excel(name = "主谈人", width = 20, orderNum = "17")
	@io.swagger.annotations.ApiModelProperty(value = "主谈人", name = "talkUserMain")
	private String talkUserMain;

	@Excel(name = "辅谈人", width = 20, orderNum = "18")
	@io.swagger.annotations.ApiModelProperty(value = "辅谈人", name = "talkUserAux")
	private String talkUserAux;

	@io.swagger.annotations.ApiModelProperty(value = "开始时间", name = "startTime")
    private transient Date starttime;

	@io.swagger.annotations.ApiModelProperty(value = "结束时间", name = "endTime")
    private transient Date endtime;

	@io.swagger.annotations.ApiModelProperty(value = "昵称", name = "userName")
	private transient String userName;
	@io.swagger.annotations.ApiModelProperty(value = "联系方式", name = "phone")
	private transient String phone;
	@io.swagger.annotations.ApiModelProperty(value = "卷名称", name = "couponName")
	private transient String couponName;

	public String getShopsStr() {
		if (shopVos != null && shopVos.size() > 0) {
			return String.join("\n",
					shopVos.stream().map(
							s->{return s.getBuildingName()+"-"+s.getFloorName()+"-"+s.getShopNumber();}
					).collect(Collectors.toList()));
		} else {
			return null;
		}
	}

	public String getUsersStr() {
		if (users != null && users.size() > 0) {
			return String.join("\n",
					users.stream().map(
							u->{return u.getName()+"-"+u.getPhone();}
					).collect(Collectors.toList()));
		} else {
			return null;
		}
	}

	public String getBusinessName() {
		return EnumBusiness.getEnumMessage(businessId);
	}

	public String getSubBusinessName() {
		return EnumSubBusiness.getEnumMessage(subBusinessId);
	}

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="单价",name="price")
	private BigDecimal price;

	@TableField(exist = false)
	private Integer receivePeriod;

	@TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value="账户参数",name="accountParameter")
	private String accountParameter;
	@TableField(exist = false)
	private List<Map<String,Object>> shoplist;
	@TableField(exist = false)
	private WxMerchantCorp wxMerchantCorp;
	@TableField(exist = false)
	private WxMerchantTax wxMerchantTax;
	@TableField(exist = false)
	private List<WxLevelConfig> levelConfigList;
	@TableField(exist = false)
	private Integer rentShopType;
    @TableField(exist = false)
    private Integer isUse;
	@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
	private String tenantId;
	@io.swagger.annotations.ApiModelProperty(value="商户图片",name="imgUrl")
	private String imgUrl;
	@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
	private Date updateDate;
	@io.swagger.annotations.ApiModelProperty(value="停车厂商(1:ETCP)",name="carVendorType")
	private Integer carVendorType;
	@io.swagger.annotations.ApiModelProperty(value="停车厂商参数",name="carParams")
	private String carParams;
	@io.swagger.annotations.ApiModelProperty(value="经营业态ID:参照wx_business表",name="businessId")
	private Integer businessId;
	@io.swagger.annotations.ApiModelProperty(value="子业态",name="subBusinessId")
	private Integer subBusinessId;
	@io.swagger.annotations.ApiModelProperty(value="店铺类型:1直营店2加盟店3个体店4旗舰店",name="shopType")
	private Integer shopType;
	@io.swagger.annotations.ApiModelProperty(value="品牌",name="brand")
	private Long brand;
    @io.swagger.annotations.ApiModelProperty(value = "类型", name = "type")
    private Integer type;
	@io.swagger.annotations.ApiModelProperty(value = "邮件", name = "email")
	private String email;
	@io.swagger.annotations.ApiModelProperty(value = "副标题", name = "title")
	private String title;
	@io.swagger.annotations.ApiModelProperty(value = "封面图", name = "coverPicture")
	private String coverPicture;
	@io.swagger.annotations.ApiModelProperty(value="是否为商管商户 1是 0否",name="status")
	private Integer isAdmin;
	@io.swagger.annotations.ApiModelProperty(value = "置顶时间", name = "topTime")
	private Date topTime;
	@io.swagger.annotations.ApiModelProperty(value="二维码地址",name="qrCode")
	private String qrCode;
	@io.swagger.annotations.ApiModelProperty(value="简介",name="introduction")
	private String introduction;
    @io.swagger.annotations.ApiModelProperty(value="优惠活动",name="actionDesc")
    private String actionDesc;
    @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = "isDel")
    private Integer isDel;
	@io.swagger.annotations.ApiModelProperty(value = "客服电话", name = "linkLinePhone")
	private String linkLinePhone;

	@TableField(exist = false)
    private WxProfitSharingReceiver wxProfitSharingReceiver;

    public String getWeappPath() {
        if(id == null)
            return "pages/index/index";
        return "pages/index/index?type=md&id=" + id;
    }

    public String getWeappScene() {
        if(id == null)
            return "";
        return "t:md:" + id;
    }

	@io.swagger.annotations.ApiModelProperty(value = "积分锁定0正常1锁定", name = "creditLocked")
	private Integer creditLocked;

	@TableField(exist = false)
	@SortColumn(column = "couponSale")
	private String couponSale;

	@TableField(exist = false)
	@SortColumn(column = "couponPrice")
	private String couponPrice;

	@TableField(exist = false)
	@SortColumn(column = "tradeAmt")
	private String tradeAmt;

	@TableField(exist = false)
	@SortColumn(column = "tradeDate")
	private String tradeDate;

	@TableField(exist = false)
	@SortColumn(column = "consumeCountP")
	private String consumeCountP;

	@TableField(exist = false)
	@SortColumn(column = "consumeCount")
	private String consumeCount;

	@io.swagger.annotations.ApiModelProperty(value = "1已关联合同", name = "hasContract")
	@TableField(exist = false)
	private Integer hasContract;
}
