package com.muyu.domain;

import com.alibaba.fastjson2.annotation.JSONField;
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 lombok.*;
import lombok.experimental.SuperBuilder;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
 * 电子围栏类
 * @Author：yang
 * @Package：com.muyu.domain
 * @Project：cloud-electronic
 * @name：CarFence
 * @Date：2024/9/17 16:08
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Tag(name = "电子围栏类")
@TableName(value = "car_fence",autoResultMap = true)
public class CarFence {

    /**
     * 围栏主键
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    /**
     * 围栏名称
     */
    private String name;
    /**
     * 业务类型ID
     */
    private Integer clazzId;
    /**
     * 业务类型名称
     */
    @TableField(exist = false)
    private String clazzName;
    /**
     * 围栏类型ID
     */
    private Integer typeId;
    /**
     * 围栏类型名称
     */
    @TableField(exist = false)
    private String typeName;
    /**
     * 围栏经纬度
     */
    private String fenceText;
    /**
     * 围栏开始时间
     */
    @DateTimeFormat(fallbackPatterns = "yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    private Date fenceStart;
    /**
     * 围栏结束时间
     */
    @DateTimeFormat(fallbackPatterns = "yyyy-MM-dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    private Date fenceEnd;
    /**
     * 创建时间
     */
    @DateTimeFormat(fallbackPatterns = "yyyy/MM/dd hh:mm:ss")
    @JsonFormat(pattern = "yyyy/MM/dd hh:mm:ss")
    private Date fenceCreate;
    /**
     * 中间表ID
     */
    private Integer middleId;
    /**
     * 围栏组
     */
    @TableField(exist = false)
    private List<CarFenceGroup> carFenceGroups;

    public static CarFence carFenceBuild(CarFence carFence) {
        return CarFence.builder()
                .id(carFence.getId())
                .name(carFence.getName())
                .clazzId(carFence.getClazzId())
                .typeId(carFence.getTypeId())
                .fenceText(carFence.getFenceText())
                .fenceStart(carFence.getFenceStart())
                .fenceCreate(carFence.getFenceCreate())
                .middleId(carFence.getMiddleId())
                .build();
    }
}
