package cn.ysk.cashier.mybatis.entity;

import java.util.Date;

import cn.hutool.core.collection.CollectionUtil;
import cn.ysk.cashier.utils.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 店铺分享(TbShopShare)表实体类
 *
 * @author ww
 * @since 2024-11-06 15:47:37
 */
@Data
@SuppressWarnings("serial")
public class TbShopShare extends Model<TbShopShare> {

    @TableId(type = IdType.AUTO)
    private Integer id;
    //店铺Id
    private Integer shopId;
    //标题
    private String title;
    //分享封面图
    private String shareImg;
    //邀请顶部图
    private String invitedImg;
    //被邀顶部图
    private String beInvitedImg;
    //活动结束时间
    private String endTime;
    //活动开始时间
    private String startTime;
    //新用户获得券
    private String newCoupon;
    //邀请num人数 可获奖励券
    private Integer invitedNum;
    //奖励券
    private String rewardCoupon;
    //获取方法 get-新用户领取获得 use-新用户使用获得
    private String getMethod;

    private Integer status;

    @TableField(exist = false)
    private List<ShareCoupons> newCoupons;

    @TableField(exist = false)
    private List<ShareCoupons> rewardCoupons;

    public void setNewCoupon(String newCoupon) {
        this.newCoupon = newCoupon;
        if(StringUtils.isNotBlank(newCoupon)){
            this.newCoupons = JSONUtil.parseJSONStrTList(newCoupon,ShareCoupons.class);
        }
    }

    public void setRewardCoupon(String rewardCoupon) {
        this.rewardCoupon = rewardCoupon;
        if(StringUtils.isNotBlank(rewardCoupon)){
            this.rewardCoupons = JSONUtil.parseJSONStrTList(rewardCoupon,ShareCoupons.class);
        }
    }

    public void setNewCoupons(List<ShareCoupons> newCoupons) {
        this.newCoupons = newCoupons;
        if(CollectionUtil.isNotEmpty(newCoupons)){
            this.newCoupon = JSONUtil.toJSONString(newCoupons);
        }
    }

    public void setRewardCoupons(List<ShareCoupons> rewardCoupons) {
        this.rewardCoupons = rewardCoupons;
        if(CollectionUtil.isNotEmpty(rewardCoupons)){
            this.rewardCoupon = JSONUtil.toJSONString(rewardCoupons);
        }
    }

    @Data
    public static class ShareCoupons {
        //优惠券Id
        private Integer couponId;
        //优惠券名称
        private String couponName;
        //优惠券数量
        private Integer couponNum;
    }
}

