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

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
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.validation.constraints.*;
import javax.persistence.Entity;
import javax.persistence.Table;

import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.dm.dmReadingRoomApplay.domain.DmReadingRoomApplay;
import me.zhengjie.modules.dm.dmtsInfo.domain.DmTsInfo;
import me.zhengjie.modules.dmuser.domain.DmUser;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.List;

/**
* @website https://el-admin.vip
* @description /
* @author longda
* @date 2022-02-25
**/
@Entity
@Data
@Table(name="dm_reading_room")
public class DmReadingRoom extends BaseEntity implements Serializable {

    @Id
    @Column(name = "reading_room_id")
    @ApiModelProperty(value = "记录id")
    @JSONField(serializeUsing= ToStringSerializer.class)
    @NotNull(groups = {Update.class,Create.class})
    private Long readingRoomId;

//    @Column(name = "book_id",nullable = false)
//    @NotNull
//    @ApiModelProperty(value = "书籍id")
//    private Long bookId;

    @Column(name = "book_name")
    @ApiModelProperty(value = "书籍名称")
    private String bookName;

    @Column(name = "read_start_time")
    @ApiModelProperty(value = "借阅起始时间")
    private Timestamp readStartTime;

    @Column(name = "read_end_time")
    @ApiModelProperty(value = "借阅到期时间")
    private Timestamp readEndTime;

    @Column(name = "is_overdue")
    @ApiModelProperty(value = "是否逾期 0 未逾期 1 逾期")
    private Integer isOverdue;

    @Column(name = "overdue_day")
    @ApiModelProperty(value = "逾期天数")
    private Integer overdueDay;

    @Column(name = "return_time")
    @ApiModelProperty(value = "归还时间")
    private Timestamp returnTime;

//    @Column(name = "borrow_user_id")
//    @ApiModelProperty(value = "借阅人id")
//    private String borrowUserId;

    @Column(name = "borrow_money")
    @ApiModelProperty(value = "借阅金额")
    private BigDecimal borrowMoney;


    @Column(name = "borrow_user_name")
    @ApiModelProperty(value = "借阅人姓名")
    private String borrowUserName;

//    @Column(name = "borrow_user_card")
//    @ApiModelProperty(value = "借书证号码")
//    private String borrowUserCard;

    @OneToOne
    @ApiModelProperty("借阅人信息")
    @JoinColumn(name = "borrow_user_id",referencedColumnName = "id")
    @NotFound(action = NotFoundAction.IGNORE)
    private DmUser dmUser;

    @Column(name = "collection_sin")
    @ApiModelProperty(value = "图书藏id")
    private String collectionSin;

    @Column(name = "borrow_status")
    @ApiModelProperty(value = "O  借出   I 归还")
    private String borrowStatus;

    @OneToOne
    @ApiModelProperty(value = "图书信息")
    @JoinColumn(name = "book_id",referencedColumnName = "ts_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private DmTsInfo dmTsInfo;

    @OneToMany(fetch = FetchType.EAGER)
    @ApiModelProperty(value = "消费记录")
    @JoinColumn(name = "reading_room_id",referencedColumnName = "reading_room_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private List<DmReadingRoomApplay> dmReadingRoomApplayList;

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