/*
*  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 com.youchain.businessdata.domain;

import com.youchain.base.BaseEntity;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Stock;
import com.youchain.modules.system.domain.Dept;
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 org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @website https://eladmin.vip
* @description /
* @author huojin
* @date 2023-08-22
**/
@Entity
@Data
@Table(name="data_inventory")
public class Inventory  extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "ID")
    private Long id;

    @Column(name = "`bill_code`")
    @ApiModelProperty(value = "单据号")
    private String billCode;

    @OneToOne
    @JoinColumn(name = "`item_key_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "物料属性")
    private ItemKey itemKey;

    @OneToOne
    @JoinColumn(name = "`point_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "点位")
    private Point point;

    @Column(name = "`point_code`")
    @ApiModelProperty(value = "点位号")
    private String pointCode;


    @OneToOne
    @JoinColumn(name = "`stock_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "容器")
    private Stock stock;

    @Column(name = "`stock_code`")
    @ApiModelProperty(value = "容器号")
    private String stockCode;


    @OneToOne
    @JoinColumn(name = "`big_stock_id`",nullable = true)
    @NotNull
    @ApiModelProperty(value = "大容器")
    private Stock bigStock;

    @Column(name = "`quantity`")
    @ApiModelProperty(value = "数量")
    private Double quantity=0d;

    @Column(name = "`queued_qty`")
    @ApiModelProperty(value = "分配数")
    private Double queuedQty=0d;

    @Column(name = "`weight`")
    @ApiModelProperty(value = "重量")
    private Double weight=0d;

    @Column(name = "`volume`")
    @ApiModelProperty(value = "体积")
    private Double volume=0d;

    @Column(name = "`description`")
    @ApiModelProperty(value = "描述")
    private String description;

    @Column(name = "`be_lock`")
    @ApiModelProperty(value = "检验")
    private Boolean beLock=true;

    @Column(name = "`be_reject`")
    @ApiModelProperty(value = "是否不良品")
    private Boolean beReject=false;

    @Column(name = "`status`")
    @ApiModelProperty(value = "状态")
    private String status;

    @Column(name = "`storage_date`")
    @ApiModelProperty(value = "存货日期")
    private Timestamp storageDate;


    @OneToOne
    @JoinColumn(name = "`dept_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "仓库")
    private Dept dept;




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

    public void addQty(Inventory inv,double qty){
        inv.setQuantity(inv.getQuantity()+qty);
    }
}
