/*
*  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.ykt.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;

import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.dm.dmCard.domain.DmCard;
import me.zhengjie.modules.dmuser.domain.DmUser;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import java.sql.Timestamp;
import java.io.Serializable;
import java.util.List;

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

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

    @OneToOne
    @JoinColumn(name = "card_number",referencedColumnName = "card_number")
    @ApiModelProperty(value = "卡")
    private DmCard dmCard;

    @OneToOne
    @JoinColumn(name = "user_number",referencedColumnName = "id")
    @ApiModelProperty(value = "用户")
    private DmUser userNumber;

    @Column(name = "user_name")
    @ApiModelProperty(value = "用户名称")
    private String userName;

    @Column(name = "user_phone")
    @ApiModelProperty(value = "用户手机号")
    private String userPhone;

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

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

    @Column(name = "end_time")
    @ApiModelProperty(value = "有效结束时间")
//    @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    private Timestamp endTime;

    @Column(name = "vehicle_type")
    @ApiModelProperty(value = "车辆类型(00-员工车辆,01-白名单,02-访客车辆)")
    private String vehicleType;

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

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

    @Column(name = "type")
    @ApiModelProperty(value = "状态(00-app、01-web)")
    private String type;

    @Column(name = "remark")
    @ApiModelProperty(value = "备注")
    private String remark;

    @Column(name = "enabled")
    @ApiModelProperty(value = "app是否审核")
    private String enabled;

    @Column(name = "task_id")
    @ApiModelProperty(value = "任务id")
    private String taskId;

    @Column(name = "approve_suggest")
    @ApiModelProperty(value = "审批者意见")
    private String approveSuggest;


    /* 扩展关联 */
//    @ApiModelProperty(value = "卡表")
//    @Transient
//    @ManyToMany(fetch = FetchType.EAGER)
//    @JoinTable(name = "dm_card",
//            joinColumns = {@JoinColumn(name = "id",referencedColumnName = "id")},
//            inverseJoinColumns = {@JoinColumn(name = "id",referencedColumnName = "id")})
//    public List<DmCard> dmCardList;

    @OneToMany
    @ApiModelProperty(value = "车牌设备对应表")
    @JoinTable(name = "dm_plate_device",
            joinColumns = {@JoinColumn(name = "plate_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "device_id",referencedColumnName = "id")})
    @NotFound(action = NotFoundAction.IGNORE)
    private List<DmRoomDevice> dmRoomDevices;

    @Transient
    @ApiModelProperty(value = "车辆类型")
    public Long cheliangType;

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