package com.muyu.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.domain.req.VehicleAddReq;
import com.muyu.domain.req.VehicleUpdReq;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

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

/**
 *  车辆表
 * @Author: LiDongJia
 * @Package: com.muyu.vehicle.domain
 * @Project: 2112-car-cloud-server
 * @name: Vehicle
 * @Date: 2024/9/16  15:24
 * @Description: 车辆信息实体类
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "vehicle", autoResultMap = true)
public class Vehicle extends BaseEntity {

    /**
     * 车辆主键
     */
    @Excel(name = "车辆主键", cellType = ColumnType.NUMERIC)
    @TableId(value = "vehicle_id", type = IdType.AUTO)
    @Schema(type = "Long",description = "车辆主键")
    private Long vehicleId;

    /**
     * 车牌号
     */
    @Schema(type = "String",description = "车牌号")
    @Excel(name = "车牌号")
    private String licenceNumber;

    /**
     * 车辆颜色
     */
    @Schema(type = "String",description = "车辆颜色")
    @Excel(name = "车辆颜色")
    private String vehicleColor;

    /**
     * 车辆VIN
     */
    @Schema(type = "String",description = "车辆VIN")
    @Excel(name = "车辆VIN")
    private String vehicleVin;

    /**
     * 车辆类型外键
     */
    @Schema(type = "Long",description = "车辆类型外键")
    @Excel(name = "车辆类型外键")
    private Long vehicleTypeId;

    /**
     * 车辆品牌
     */
    @Schema(type = "String",description = "车辆品牌")
    @Excel(name = "车辆品牌")
    private String vehicleBrand;

    /**
     * 车辆型号
     */
    @Schema(type = "String",description = "车辆型号")
    @Excel(name = "车辆型号")
    private String vehicleModel;

    /**
     * 车辆行驶证
     */
    @Schema(type = "String",description = "车辆行驶证")
    @Excel(name = "车辆行驶证")
    private String vehicleLicense;

    /**
     * 行驶证到期日期
     */
    @Schema(type = "Date",description = "行驶证到期日期")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date vehicleLicenseDueDate;

    /**
     * 车辆状态
     */
    @Schema(type = "String",description = "车辆状态")
    @Excel(name = "车辆状态")
    private String vehicleStatus;

    /**
     * 车辆所属企业外键
     */
    @Schema(type = "Long",description = "车辆所属企业外键")
    private Long companyId;

    /**
     * 电子围栏外键
     */
    @Schema(type = "Integer",description = "电子围栏外键")
    private Integer fenceGroupId;

    /** 策略id */
    @Schema(type = "Long",description = "策略id")
    private Long warnStrategyId;

    public static Vehicle addBuild(VehicleAddReq vehicleAddReq){
        return Vehicle.builder()
                .licenceNumber(vehicleAddReq.getLicenceNumber())
                .vehicleColor(vehicleAddReq.getVehicleColor())
                .vehicleVin(vehicleAddReq.getVehicleVin())
                .vehicleTypeId(vehicleAddReq.getVehicleTypeId())
                .vehicleBrand(vehicleAddReq.getVehicleBrand())
                .vehicleModel(vehicleAddReq.getVehicleModel())
                .vehicleLicense(vehicleAddReq.getVehicleLicense())
                .vehicleLicenseDueDate(vehicleAddReq.getVehicleLicenseDueDate())
                .vehicleStatus(vehicleAddReq.getVehicleStatus())
                .companyId(vehicleAddReq.getCompanyId())
                .fenceGroupId(vehicleAddReq.getFenceGroupId())
                .warnStrategyId(vehicleAddReq.getWarnStrategyId())
                .build();
    }

    public static Vehicle updBuild(VehicleUpdReq vehicleUpdReq, Supplier<Long> idSupplier){
        return Vehicle.builder()
                .vehicleId(idSupplier.get())
                .licenceNumber(vehicleUpdReq.getLicenceNumber())
                .vehicleColor(vehicleUpdReq.getVehicleColor())
                .vehicleVin(vehicleUpdReq.getVehicleVin())
                .vehicleTypeId(vehicleUpdReq.getVehicleTypeId())
                .vehicleBrand(vehicleUpdReq.getVehicleBrand())
                .vehicleModel(vehicleUpdReq.getVehicleModel())
                .vehicleLicense(vehicleUpdReq.getVehicleLicense())
                .vehicleLicenseDueDate(vehicleUpdReq.getVehicleLicenseDueDate())
                .vehicleStatus(vehicleUpdReq.getVehicleStatus())
                .companyId(vehicleUpdReq.getCompanyId())
                .fenceGroupId(vehicleUpdReq.getFenceGroupId())
                .warnStrategyId(vehicleUpdReq.getWarnStrategyId())
                .build();
    }

}
