package com.fzm.mall.server.admin.shop.model;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fzm.mall.server.admin.home_page.dao.AdminMapper;
import com.fzm.mall.server.admin.home_page.model.Admin;
import com.fzm.mall.server.admin.util.UUIDUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * <p>
 * 店铺中心-店铺
 * </p>
 *
 * @author wulixian
 * @since 2021-03-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("shop")
@ApiModel(value = "Shop对象", description = "店铺中心-店铺")
public class Shop implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 商铺状态-有效：1
     */
    public static final Integer SHOP_STATUS_VALID = 1;

    /**
     * 商铺状态-无效：0
     */
    public static final Integer SHOP_STATUS_INVALID = 0;

    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "商户号")
    private String merchantId;

    @ApiModelProperty(value = "店铺编号")
    private String shopId;

    @ApiModelProperty(value = "店铺名称")
    private String shopName;

    @ApiModelProperty(value = "店铺介绍")
    private String introduction;

    @ApiModelProperty(value = "店铺联系人")
    private String contact;

    @ApiModelProperty(value = "联系方式")
    private String contactPhone;

    @ApiModelProperty(value = "店铺联系地址")
    private String shopAddress;

    @ApiModelProperty(value = "店铺头像url")
    private String shopImage;

    @ApiModelProperty(value = "店铺状态(1->有效;2->无效)")
    private Integer status;

    @ApiModelProperty(value = "信息入库时间")
    @TableField(fill = FieldFill.INSERT)
    private Long createTime;

    @ApiModelProperty(value = "信息更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateTime;

    @TableField(exist = false)
    private String adminId;

    public void init() {
        setShopId(UUIDUtil.getUUID());
        setStatus(SHOP_STATUS_VALID);
    }

    /**
     * 设置店铺账号的客服
     *
     * @param adminMapper
     */
    public void updateShopCustomer(AdminMapper adminMapper) {
        Admin admin = new Admin();
        admin.setMerchantId(this.merchantId);
        admin.setUser(this.shopName);
        admin.setAdminId(this.adminId);

        UpdateWrapper<Admin> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("merchant_id", this.merchantId).eq("admin_id", this.adminId);

        adminMapper.update(admin, updateWrapper);
    }
}
