package com.muyu.web.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.function.Supplier;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("vehicle_info")
public class VehicleInfo {

    /**
     * 主键
     */
    @TableId(
            value = "id",
            type = IdType.AUTO
    )
    private Long id;
    /**
     * VIN
     */
    private String vin;
    /**
     * VIN
     */
    @TableField(value = "tenant_id", fill = FieldFill.INSERT)
    private String tenantId;

    /**
     * 报文模板
     */
    @TableField("message_template_id")
    private Long messageTemplateId;

    /**
     * 电池剩余电量
     */
    @TableField("remaining_battery")
    private BigDecimal remainingBattery;

    /**
     * 电池电量
     */
    @TableField("battery_level")
    private BigDecimal batteryLevel;

    /**
     * 上一次经度
     */
    @TableField("last_longitude")
    private String lastLongitude;

    /**
     * 上一次维度
     */
    @TableField("last_latitude")
    private String lastLatitude;

    /**
     * 总里程
     */
    @TableField("total_mileage")
    private BigDecimal totalMileage;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;


    public static  VehicleInfo create(String vin, Supplier<Long>messageTemplateId){
     return    VehicleInfo.builder()
                .vin(vin)
                .messageTemplateId(messageTemplateId.get())
                .createTime(new Date())
                .totalMileage(BigDecimal.ZERO)
                .build();
    }



}
