package jnpf.model.personnels.dto.goods;

import jnpf.model.personnels.po.FtbPersonnelsGoods;
import lombok.Data;

import javax.validation.constraints.*;
import java.io.Serializable;

/**
 * 人员物品管理表单
 *
 * @author admin
 * @create 2025-09-11
 */
@Data
public class FtbPersonnelsGoodsFormDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 物品名称
     */
    @NotBlank(message = "物品名称不能为空")
    @Size(max = 50, message = "物品名称长度不能超过50")
    private String goodsName;

    /**
     * 物品编号
     */
    @NotBlank(message = "物品编号不能为空")
    @Size(max = 10, message = "物品编号长度不能超过10")
    @Pattern(regexp = "^[a-zA-Z0-9-]+$", message = "物品编号只能包含字母（大小写）、-、数字")
    private String goodsCode;

    /**
     * 是否需要归还（0-否，1-是）
     */
    @NotNull(message = "是否需要归还不能为空")
    private Integer needReturn;

    /**
     * 物品数量，数字型，正整数，范围1～10000
     */
    @NotNull(message = "物品数量不能为空")
    @Min(value = 1, message = "物品数量必须大于0")
    @Digits(integer = 6, fraction = 0, message = "物品数量必须是正整数，范围1～100000")
    private Long quantity;

    /**
     * 备注
     */
    @Size(max = 500, message = "备注长度不能超过500个字符")
    private String remark;

    public FtbPersonnelsGoods convert(FtbPersonnelsGoodsFormDTO ftbPersonnelsGoodsFormDTO) {
        if (ftbPersonnelsGoodsFormDTO == null) {
            return null;
        }
        FtbPersonnelsGoods ftbPersonnelsGoods = new FtbPersonnelsGoods();
        ftbPersonnelsGoods.setGoodsName(ftbPersonnelsGoodsFormDTO.getGoodsName());
        ftbPersonnelsGoods.setGoodsCode(ftbPersonnelsGoodsFormDTO.getGoodsCode());
        ftbPersonnelsGoods.setNeedReturn(ftbPersonnelsGoodsFormDTO.getNeedReturn());
        ftbPersonnelsGoods.setQuantity(ftbPersonnelsGoodsFormDTO.getQuantity());
        ftbPersonnelsGoods.setReturnedQuantity(ftbPersonnelsGoodsFormDTO.getQuantity());
        ftbPersonnelsGoods.setRemark(ftbPersonnelsGoodsFormDTO.getRemark());
        return ftbPersonnelsGoods;
    }
}