package com.gci.boot.modules.vehicles.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
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 com.fasterxml.jackson.annotation.JsonFormat;
import com.gci.boot.annotation.Query.SelectQuery;
import com.gci.boot.common.dict.annotation.Dict;
import com.gci.boot.common.dict.excel.DictConverter;
import com.gci.boot.common.util.ValidatorUtil;
import com.gci.boot.common.validated.ImportValidated;
import com.gci.boot.common.validated.SaveValidated;
import com.gci.boot.common.validated.UpdateValidated;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 加油充电登记
 * </p>
 *
 * @author admin
 * @since 2023-11-30
 */
@Data
@ColumnWidth(20)
public class TbRefuelChargeRecordImportVo {

    @ValidatorUtil.NotEmpty(message = "日期不能为空")
    @ValidatorUtil.DateValue(format = "yyyy-MM-dd", message = "日期格式错误:格式为'yyyy-MM-dd'")
    @ExcelProperty("日期")
    @DateTimeFormat("yyyy-MM-dd")
    private String recordDate;

    @ValidatorUtil.StrMaxLength(strMaxLength = 64, message = "单号长度不能超过64位", fieldNameCN = "单号")
    @ExcelProperty("单号")
    private String orderNo;

    @ValidatorUtil.DateValue(format = "HH:mm:ss", message = "开始时间错误:格式为'HH:mm:ss'")
    @ExcelProperty(value = "开始时间")
    @DateTimeFormat("HH:mm:ss")
    private String startTime;

    @ValidatorUtil.DateValue(format = "HH:mm:ss", message = "结束时间错误:格式为'HH:mm:ss'")
    @ExcelProperty(value = "结束时间")
    @DateTimeFormat("HH:mm:ss")
    private String endTime;

    @ValidatorUtil.NotEmpty(message = "车牌号不能为空")
    @ExcelProperty(value = "车牌号")
    private String plateNumber;

    @ValidatorUtil.NotEmpty(message = "卡号不能为空")
    @ValidatorUtil.StrMaxLength(strMaxLength = 32, message = "卡号不能超过32位", fieldNameCN = "卡号")
    @ExcelProperty(value = "卡号")
    private String oilCard;

    @ValidatorUtil.NotEmpty(message = "油品规格不能为空")
    @ValidatorUtil.CollectionStr(collectionStr = "0号 车用柴油(Ⅵ),92号 车用汽油(ⅥB),95号 车用汽油(ⅥB),充电",
            message = "油品规格只能为'0号 车用柴油(Ⅵ)'、'92号 车用汽油(ⅥB)'、'95号 车用汽油(ⅥB)'、'充电'")
    @ExcelProperty(value = "油品规格")
    private String oilType;

    @ValidatorUtil.NotEmpty(message = "数量（升/度）不能为空")
    @ValidatorUtil.NumericValue(minValue= 0, maxValue = 999999,  message = "数量（升/度）必须为数字:且范围在[0,999999]")
    @ExcelProperty(value = "数量（升/度）")
    private String amount;

    @ValidatorUtil.NotEmpty(message = "金额（元）不能为空")
    @ValidatorUtil.NumericValue(minValue= 0, maxValue = 999999,  message = "金额（元）必须为数字:且范围在[0,999999]")
    @ExcelProperty(value = "金额（元）")
    private String totalPrice;

    @ValidatorUtil.NotEmpty(message = "加油（充电）时里程（km）不能为空")
    @ValidatorUtil.NumericValue(minValue= 0, maxValue = 999999,  message = "加油（充电）时里程（km）必须为数字:且范围在[0,999999]")
    @ExcelProperty(value = "加油（充电）时里程（km）")
    private String mileage;

    @ValidatorUtil.StrMaxLength(strMaxLength = 1000, message = "备注长度不能超过1000位", fieldNameCN = "备注")
    @ExcelProperty(value = "备注")
    private String remark;

    @ValidatorUtil.StrMaxLength(strMaxLength = 64, message = "驾驶员长度不能超过64位", fieldNameCN = "驾驶员")
    @ExcelProperty(value = "驾驶员")
    private String driver;
    @ValidatorUtil.StrMaxLength(strMaxLength = 64, message = "加油站长度不能超过64位", fieldNameCN = "加油站")
    @ExcelProperty(value = "加油站")
    private String oilStation;
    @ValidatorUtil.NumericValue(minValue= 0, maxValue = 999999,  message = "卡余额(元)必须为数字:且范围在[0,999999]")
    @ExcelProperty(value = "卡余额(元)")
    private BigDecimal oilCardBalance;

    @ExcelIgnore
    @TableField(exist = false)
    private List<String> validationErrors;
    @ExcelProperty("异常信息")
    @TableField(exist = false)
    private String validationErrorsStr;
    public void validate() {
        ValidatorUtil.trimStringFields(this);
        List<ValidatorUtil.ValidationError> validationErrors = ValidatorUtil.validate(this);
        if(CollectionUtil.isNotEmpty(validationErrors)){
            this.validationErrors  = validationErrors.stream().map(ValidatorUtil.ValidationError::getMessage).collect(Collectors.toList());
            this.validationErrorsStr = this.validationErrors + "";
        }
    }
    public void putErrorMsg(String msg){
        if(CollectionUtil.isNotEmpty(this.validationErrors)){
            this.validationErrors.add(msg);
        }else{
            this.validationErrors = CollectionUtil.newArrayList(msg);
        }
        this.validationErrorsStr = this.validationErrors + "";
    }

}
