package com.cf.imes.module.manage.controller.admin.plate.vo.plate;

import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;

/**
 * 用户 Excel 导入 VO
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = false) // 设置 chain = false，避免用户导入有问题
public class PlateImportExcelVO {

    @ExcelProperty("商品编号")
    @NotEmpty(message = "商品编号不能为空")
    private String goodsId;

    @ExcelProperty("商品名称")
    @NotEmpty(message = "商品名称不能为空")
    private String goodsName;

    @ExcelProperty("材质")
    @NotEmpty(message = "材质不能为空")
    private String material;

    @ExcelProperty("颜色")
    @NotEmpty(message = "颜色不能为空")
    private String color;

    @ExcelProperty("纹路")
    @NotEmpty(message = "纹路不能为空")
    private String texture;

    @ExcelProperty("宽度")
    @NotEmpty(message = "宽度不能为空")
    private String width;

    @ExcelProperty("高度")// float(8,3)
    @NotEmpty(message = "高度不能为空")
    private String height;

    @ExcelProperty("厚度")
    @NotEmpty(message = "厚度不能为空")
    private String thickness;

    @ExcelProperty("价格")
    @NotEmpty(message = "价格不能为空")
    private String price;

    @ExcelProperty("品牌")
    @NotEmpty(message = "品牌不能为空")
    private String brand;

    @ExcelProperty("规格")
    @NotEmpty(message = "规格不能为空")
    private String spec;

    @ExcelProperty("备注")
    private String remark;

    @ExcelProperty("上传结果")
    private String result;

    public boolean isValidGoods() {
        return !(goodsId == null || goodsId.isEmpty() || goodsName == null || goodsName.isEmpty() || material == null ||
                material.isEmpty() || color == null || color.isEmpty() || width == null ||width.isEmpty() || height == null ||
                height.isEmpty() || height == null ||thickness.isEmpty() || brand == null || brand.isEmpty() || spec == null || spec.isEmpty());
    }

//    数据长度判断
    public boolean checkPrecision(Double number) {
        if (number == null) {
            return false;
        }
        // 将浮点数转换成字符串
        String numberStr = Double.toString(number);

        // 分割整数部分和小数部分
        String[] parts = numberStr.split("\\.");
        String integerPart = parts[0];
        String decimalPart = parts.length > 1 ? parts[1] : "";

        // 检查整数部分位数
        if (integerPart.length() > 5) {
            return false;
        }

        // 检查小数部分位数
        if (decimalPart.length() > 3) {
            return false;
        }

        return true;
    }
}
