/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.dm.plateNumber.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.modules.dm.roomDevice.domain.DmRoomDevice;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Set;

/**
* @website https://el-admin.vip
* @description /
* @author Zheng Jie
* @date 2021-11-27
**/
@Entity
@Data
@Table(name="dm_plate_number")
public class DmPlateNumber implements Serializable {

    @Id
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "user_number",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "用户")
    private String userNumber;

    @Column(name = "plate_number")
    @ApiModelProperty(value = "车牌号")
    private String plateNumber;

    @Column(name = "start_time")
    @ApiModelProperty(value = "有效开始时间")
    private Timestamp startTime;

    @Column(name = "end_time")
    @ApiModelProperty(value = "有效结束时间")
    private Timestamp endTime;

    @Column(name = "effective_state")
    @ApiModelProperty(value = "效期状态(00-有效、01-过期)")
    private String effectiveState;

    @Column(name = "registration_status")
    @ApiModelProperty(value = "登记状态(00-待审核、01-已登记)")
    private String registrationStatus;

    @Column(name = "create_by")
    @ApiModelProperty(value = "创建者")
    private String createBy;

    @Column(name = "update_by")
    @ApiModelProperty(value = "更新者")
    private String updateBy;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Timestamp createTime;

    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间")
    private Timestamp updateTime;

    @ManyToMany
    @ApiModelProperty(value = "车牌设备")
    @JoinTable(name = "dm_plate_device",
            joinColumns = {@JoinColumn(name = "plate_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "device_id",referencedColumnName = "id")})
    private Set<DmRoomDevice> dmRoomDevices;

    public void copy(DmPlateNumber source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}