package com.liquidnet.service.kylin.dto.param;

import com.liquidnet.service.kylin.entity.KylinOrderRefundReasons;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 退款原因配置参数
 */
@Data
@ApiModel("退款原因配置参数")
public class OrderRefundReasonParam {

    @ApiModelProperty(value = "原因业务ID")
    private String reasonId;

    @ApiModelProperty(value = "退款理由名称")
    private String name;

    @ApiModelProperty(value = "是否需要二级补充输入 0否 1是")
    private Integer needDetail;

    @ApiModelProperty(value = "二级输入placeholder")
    private String placeholder;

    @ApiModelProperty(value = "是否已应用 0未应用 1应用中")
    private Integer isApplied;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ApiModelProperty(value = "批量操作ID列表")
    private List<String> ids;

    public KylinOrderRefundReasons getFields(String reasonId, LocalDateTime createdAt) {
        KylinOrderRefundReasons entity = new KylinOrderRefundReasons();
        BeanUtils.copyProperties(this, entity);
        if (reasonId != null) {
            entity.setReasonId(reasonId);
        }
        if (createdAt != null) {
            entity.setCreatedAt(createdAt);
        }
        if (entity.getNeedDetail() == null) {
            entity.setNeedDetail(0);
        }
        if (entity.getPlaceholder() == null) {
            entity.setPlaceholder("");
        }
        if (entity.getIsApplied() == null) {
            entity.setIsApplied(0);
        }
        if (entity.getIsDeleted() == null) {
            entity.setIsDeleted(0);
        }
        if (entity.getSort() == null) {
            entity.setSort(0);
        }
        if (entity.getNeedDetail() != null && entity.getNeedDetail() == 0) {
            entity.setPlaceholder("");
        }
        entity.setUpdatedAt(LocalDateTime.now());
        return entity;
    }
}
