package com.fs.store.domain;

import java.math.BigDecimal;
import java.util.List;
import java.util.StringJoiner;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fs.common.annotation.Excel;
import com.fs.common.core.domain.BaseEntity;
import com.fs.store.dto.StoreOrderProductDTO;
import lombok.Data;
import org.springframework.util.CollectionUtils;

/**
 * 商品组合套餐对象 fs_store_product_package
 *
 * @author fs
 * @date 2022-07-14
 */
@Data
public class FsStoreProductPackage extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 20 */
    private Long packageId;

    /** 标题 */
    @Excel(name = "标题")
    private String title;

    /** 描述 */
    @Excel(name = "描述")
    private String descs;

    /** 内容 */
    @Excel(name = "内容")
    private String content;

    /** 封面 */
    @Excel(name = "封面")
    private String imgUrl;

    @Excel(name = "组图")
    private String images;

    /** 金额 */
    @Excel(name = "金额")
    private BigDecimal money;

    /** 支付金额 */
    @Excel(name = "支付金额")
    private BigDecimal payMoney;

    /** 公司ID */
    @Excel(name = "公司ID")
    private Long companyId;

    @Excel(name = "部门ID")
    private Long deptId;

    private String products;

    private Integer payType;

    private Integer limitCount;

    private Integer cateId;

    private Integer sort;

    private Integer status;

    /**
     * 分期赠送优惠券-是否开启 0未开启 1开启
     */
    private Integer icgEnable;

    /**
     * 分期赠送优惠券-月数
     */
    private Integer icgMonth;


    /**
     * 分期赠送优惠券-优惠券列表(数据库存储)
     */
    @JsonIgnore
    private String icgCoupons;
    /**
     * 分期赠送优惠券-优惠券列表
     */
    private Integer[] icgCouponsId;

    public String getIcgCoupons() {
        if(icgCouponsId != null && icgCouponsId.length > 0){
            StringJoiner stringJoiner = new StringJoiner(",");
            for (Integer id : icgCouponsId) {
                stringJoiner.add(id.toString());
            }
            icgCoupons = stringJoiner.toString();
        }
        return icgCoupons;
    }

    /**
     * 获取优惠券列表ID
     * @return 优惠券列表id
     */
    public Integer[] getIcgCouponsId() {
        if (icgCouponsId == null && icgCoupons != null) {
            String[] split = icgCoupons.split(",");
            icgCouponsId = new Integer[split.length];
            for (int i = 0; i < split.length; i++) {
                icgCouponsId[i] = Integer.parseInt(split[i].trim());
            }
        }
        return icgCouponsId;
    }


    /**
     * 分期赠送优惠券-url配置
     */
    private String icgUrl;

    /**
     * 分期赠送优惠券-备注
     */
    private String icgMark;

    List<StoreOrderProductDTO> productList;

}
