package com.engine.organization.entity.scheme.dto;

import com.engine.organization.entity.scheme.param.SchemeSearchParam;
import com.engine.organization.entity.scheme.po.SchemePO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.Map;
/**
 * @Author dxfeng
 * @description:
 * @Date 2022/5/9
 * @Version V1.0
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SchemeDTO {
    /**
     * 自增主键
     */
    private long id;
    /**
     * 编号
     */
    private String schemeNo;
    /**
     * 方案名称
     */
    private String schemeName;
    /**
     * 方案说明
     */
    private String schemeDescription;
    /**
     * 禁用标记
     */
    private int forbiddenTag;
    /**
     *
     */
    private Long creator;
    /**
     *
     */
    private int deleteType;
    /**
     *
     */
    private Date createTime;
    /**
     *
     */
    private Date updateTime;

    public static SchemePO convertToPO(Map<String, Object> param, Long employeeId) {
        if (param == null) {
            return null;
        }
        return SchemePO.builder()
                .id(param.get("id") == null ? 0 : Integer.parseInt((String) param.get("id")))
                .schemeNo(param.get("scheme_no") == null ? null : (String) param.get("scheme_no"))
                .schemeName(param.get("scheme_name") == null ? null : (String) param.get("scheme_name"))
                .schemeDescription(param.get("scheme_description") == null ? null : (String) param.get("scheme_description"))
                .forbiddenTag(param.get("forbidden_tag") == null ? 0 : Integer.parseInt((String) param.get("forbidden_tag")))
                .deleteType(0)
                .createTime(new Date())
                .updateTime(new Date())
                .creator(employeeId)
                .build();
    }

    public static SchemePO convertParamToPO(SchemeSearchParam param, Long employeeId) {
        if (param == null) {
            return null;
        }
        return SchemePO.builder()
                .id(param.getId() == null ? 0 : param.getId())
                .schemeNo(param.getSchemeNo() == null ? null : param.getSchemeNo())
                .schemeName(param.getSchemeName() == null ? null : param.getSchemeName())
                .schemeDescription(param.getSchemeDescription() == null ? null : param.getSchemeDescription())
                .forbiddenTag(param.getForbiddenTag() == null ? 0 : param.getForbiddenTag() ? 0 : 1)
                .deleteType(0)
                .createTime(new Date())
                .updateTime(new Date())
                .creator(employeeId)
                .build();
    }

}
