/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package cn.ysk.cashier.pojo.product;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.ysk.cashier.vo.ProductGroupVo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
* @website https://eladmin.vip
* @description /
* @author lyf
* @date 2023-12-11
**/
@Entity
@Data
@Table(name="tb_product")
@TableName("tb_product")
public class TbProduct implements Serializable {

    @Id
    @Column(name = "`id`")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "id")
    @TableId(type = IdType.AUTO)
    private Integer id;

    @Column(name = "`shop_id`")
    @ApiModelProperty(value = "店铺id")
    private String shopId;

    @Column(name = "`name`")
    @ApiModelProperty(value = "商品名称")
    private String name;

    @Column(name = "`pack_fee`")
    @ApiModelProperty(value = "包装费")
    private BigDecimal packFee;

    @Column(name = "`low_price`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "商品最低价")
    private BigDecimal lowPrice;

    @Column(name = "`unit_id`")
    @ApiModelProperty(value = "单位Id")
    private Integer unitId;

    @Column(name = "`cover_img`")
    @ApiModelProperty(value = "商品封面图")
    private String coverImg;

    @Column(name = "`category_id`")
    @ApiModelProperty(value = "categoryId")
    private String categoryId;

    @Column(name = "`spec_id`")
    @ApiModelProperty(value = "商品规格")
    private Integer specId;

    @Column(name = "`short_title`")
    @ApiModelProperty(value = "短标题--促销语")
    private String shortTitle;

    @Column(name = "`images`")
    @ApiModelProperty(value = "商品图片（第一张为缩略图，其他为详情）")
    private String images;

    @Column(name = "`sort`")
    @ApiModelProperty(value = "排序")
    private Integer sort = 0;

    @Column(name = "`status`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "0--待审核 1审核通过 -1审核失败  -2违规下架")
    private Integer status = 0;

    @Column(name = "`is_hot`")
    @ApiModelProperty(value = "是否热销")
    private Integer isHot = 0;

    @Column(name = "`type`")
    @ApiModelProperty(value = "商品类型（属性）:普通商品 normal 套餐商品 package 称重商品 weigh 团购券 coupon")
    private String type;

    @Column(name = "`type_enum`")
    @ApiModelProperty(value = "商品规格：normal-单规格  sku-多规格")
    private String typeEnum;

    @Column(name = "`is_del`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "是否回收站 0-否，1回收站")
    private Integer isDel = 0;

    @Column(name = "`is_stock`")
    @ApiModelProperty(value = "是否开启库存")
    private Integer isStock = 1;

    @Column(name = "`is_pause_sale`")
    @ApiModelProperty(value = "是否暂停销售")
    private Integer isPauseSale = 0;

    @Column(name = "`created_at`")
    @ApiModelProperty(value = "创建时间")
    private Long createdAt;

    @Column(name = "`updated_at`")
    @ApiModelProperty(value = "更新时间")
    private Long updatedAt;

    @Column(name = "`group_type`")
    @ApiModelProperty(value = "套餐类型 0固定套餐 1可选套餐")
    private Integer groupType;

    @Column(name = "`group_snap`")
    @ApiModelProperty(value = "套餐内容")
    private String groupSnap;

    @Column(name = "spec_info")
    @ApiModelProperty(value = "specInfo")
    private String specInfo;

    @Column(name = "select_spec")
    @ApiModelProperty(value = "selectSpec")
    private String selectSpec;

    @Column(name = "spec_table_headers")
    @ApiModelProperty(value = "specTableHeaders")
    private String specTableHeaders;

    @Column(name = "group_category_id")
    @ApiModelProperty(value = "团购卷分类Id")
    private String groupCategoryId;

    @Column(name = "stock_number")
    @ApiModelProperty("库存数量")
    private Integer stockNumber = 0;

    @Column(name = "is_grounding")
    @ApiModelProperty("上下架")
    private Integer isGrounding = 1;

    @Column(name = "is_refund_stock")
    @ApiModelProperty("退款是否退回库存")
    private Integer isRefundStock = 1;

    @Column(name = "warn_line")
    @ApiModelProperty("库存警戒线")
    private Integer warnLine = 0;

    @Column(name = "show_type")
    @ApiModelProperty("堂食 table 自取 dine 配送 delivery 快递 express")
    private String showType;

    @Column(name = "weight")
    @ApiModelProperty("称重 价格/千克")
    private BigDecimal weight;

    @Column(name = "is_temp_price")
    @ApiModelProperty("是否允许临时改价")
    private Integer isTempPrice = 0;

    @Column(name = "day_limit")
    @ApiModelProperty("日销售上限")
    private Integer dayLimit = 0;

    @Column(name = "single_order_limit")
    @ApiModelProperty("每单销售上限")
    private Integer singleOrderLimit = 0;

    @Column(name = "single_people_limit")
    @ApiModelProperty("每人销售上限")
    private Integer singlePeopleLimit = 0;

    @Column(name = "days")
    @ApiModelProperty("周数组 周一,周二,周日")
    private String days;

    @Column(name = "start_time")
    @ApiModelProperty("可用开始时间")
    private String startTime;

    @Column(name = "end_time")
    @ApiModelProperty("可用结束时间")
    private String endTime;

    @Transient
    @TableField(exist = false)
    private TbProductSkuResult skuResult;

    @Transient
    @TableField(exist = false)
    private List<Map<String, Object>> specList;
    @Transient
    @TableField(exist = false)
    private List<ProductGroupVo> proGroupVo;

    public void copy(TbProduct source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
