package com.tashow.cloud.productapi.api.product.vo.prod;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tashow.cloud.productapi.api.product.vo.prodadditionalfeedates.ProdAdditionalFeeBlackVO;
import com.tashow.cloud.productapi.api.product.vo.prodemergencyresponse.ProdEmergencyInfoVO;
import com.tashow.cloud.productapi.api.product.vo.prodreservationconfig.ProdReservationInfoVO;
import com.tashow.cloud.productapi.api.product.vo.prodserviceareas.ProdServiceAreasInfoVO;
import com.tashow.cloud.productapi.api.product.dto.*;
import com.tashow.cloud.productapi.api.product.vo.prodweightrangeprices.ProdWeightRangePricesSaveInfoVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Schema(description = "商品服务配置 VO")
@Data
public class ProdServiceVO {

    @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "6943")
    private Long prodId;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @Schema(description = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @Schema(description = "新建人")
    private String creator;

    @Schema(description = "修改人")
    private String updater;

    @Schema(description = "分类名称")
    private String categoryName;

    @Schema(description = "是否开启服务区域配置0关1开")
    private Integer regionSwitch;
    @Schema(description = "服务区域配置")
    public  ProdServiceAreasInfoVO prodServiceAreasInfo;


    @Schema(description = "是否预约0关1开")
    private Integer reservationSwitch;
    @Schema(description = "预约配置")
    public ProdReservationInfoVO prodReservationConfig;

   /* public List<ProdAdditionalFeeBlackVO> getProdReservationBlackList() {
        if (prodReservationBlackList == null || prodReservationBlackList.isEmpty()) {
            return prodReservationBlackList;
        }
        return prodReservationBlackList.stream()
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

    public void setProdReservationBlackList(List<ProdAdditionalFeeBlackVO> prodReservationBlackList) {
        this.prodReservationBlackList = prodReservationBlackList;
    }*/




    @Schema(description = "是否紧急响应服务0关1开")
    private Integer emergencySwitch;
    @Schema(description = "急响应服务配置")
    public ProdEmergencyInfoVO prodEmergencyInfoVO;

    @Schema(description = "是否接单上线0关1开")
    private Integer orderLimitSwitch;
    @Schema(description = "接单上线配置")
    public ProductOrderLimitDO productOrderLimitVO;


    @Schema(description = "是否特殊日期（节假日周末什么的）0关1开")
    private Integer additionalSwitch;
    @Schema(description = "特殊日期规则配置")
    public List<ProdAdditionalFeeDatesDO> prodAdditionalFeeDatesList;

    @Schema(description = "是否特殊时段0关1开 ")
    private Integer additionalFeeSwitch;
    @Schema(description = "特殊时段规则配置 ")
    public List<ProdAdditionalFeePeriodsDO> prodAdditionalFeePeriodsList;


    @Schema(description = "是否开启体重配置0关1开")
    private Integer weightSwitch;
    @Schema(description = "体重配置")
    public ProdWeightRangePricesSaveInfoVO prodWeightConfig;


    public ProdReservationInfoVO getProdReservationConfig() {

        if (this.prodReservationConfig == null) {
            return null;
        }
        // 判断是否“逻辑上为空”
        if (isProdReservationInfoEmpty(this.prodReservationConfig)) {
            return null;
        }
        return this.prodReservationConfig;
    }

    public void setProdReservationConfig(ProdReservationInfoVO prodReservationConfig) {
        this.prodReservationConfig = prodReservationConfig;
    }

    private boolean isProdReservationInfoEmpty(ProdReservationInfoVO config) {
        if (config == null) return true;
        // 判断所有字段是否都为 null 或空
        return config.getId() == null;
    }
}