/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.finance.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ijpay.core.kit.PayKit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.common.enums.RefundStateEnum;
import org.springblade.common.enums.RefundTypeEnum;
import org.springblade.core.secure.utils.AuthUtil;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 退款信息实体类
 *
 * @author BladeX
 * @since 2022-02-13
 */
@Data
@TableName("t_order_refund")
@ApiModel(value = "OrderRefund对象", description = "退款信息")
public class OrderRefund implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 退款ID
	 */
	@JsonSerialize(using = ToStringSerializer.class)
	@TableId(value = "id", type = IdType.ASSIGN_ID)
	@ApiModelProperty(value = "退款ID")
	private Long id;
	/**
	 * 订单ID
	 */
	@ApiModelProperty(value = "订单ID")
	private Long orderId;
	/**
	 * 用户ID
	 */
	@ApiModelProperty(value = "用户ID")
	private Long userId;
	/**
	 * 退款原因
	 */
	@ApiModelProperty(value = "退款单号")
	private String refundNo;
	/**
	 * 退款状态
	 */
	@ApiModelProperty(value = "退款状态 1-申请中 2-退款成功 3-退款失败")
	private Integer refundState;
	/**
	 * 退款原因
	 */
	@ApiModelProperty(value = "退款原因")
	private String reason;
	/**
	 * 退款凭证（图片）
	 */
	@ApiModelProperty(value = "退款凭证（图片）")
	private String rimgs;
	/**
	 * 退款备注
	 */
	@ApiModelProperty(value = "退款备注")
	private String remark;
	/**
	 * 拒绝原因
	 */
	@ApiModelProperty(value = "拒绝原因")
	private String refuseReason;
	/**
	 * 退款类型  0--只退款，1--退货退款
	 */
	@ApiModelProperty(value = "退款类型  0--只退款，1--退货退款")
	private Integer refundType;
	/**
	 * 退款物流公司
	 */
	@ApiModelProperty(value = "退款物流公司")
	private String wlName;
	/**
	 * 物流单号
	 */
	@ApiModelProperty(value = "物流单号")
	private String wlNum;
	/**
	 * 退款地址
	 */
	@ApiModelProperty(value = "退款地址")
	private String shopAddress;
	/**
	 * 申请时间
	 */
	@ApiModelProperty(value = "申请时间")
	private Date createTime;
	/**
	 * 同意/拒绝时间
	 */
	@ApiModelProperty(value = "同意/拒绝时间")
	private Date agreeTime;
	/**
	 * 退款时间
	 */
	@ApiModelProperty(value = "退款时间")
	private Date refundTime;
	/**
	 * 删除标识   0正常  1逻辑删除
	 */
	@ApiModelProperty(value = "删除标识   0正常  1逻辑删除")
	private Boolean isDeleted;

	@ApiModelProperty(value = "售后id")
	private Long afterSalesId;

	@ApiModelProperty(value = "退款金额")
	private BigDecimal refuseAmount;

	public static OrderRefund build(Long orderId) {
		String outRefundNo = PayKit.generateStr();
		OrderRefund orderRefund = new OrderRefund();
		orderRefund.setRefundNo(outRefundNo);
		orderRefund.setOrderId(orderId);
		orderRefund.setRefundType(RefundTypeEnum.ONLY_REFUND.getValue());
		orderRefund.setRefundState(RefundStateEnum.ONLY_REFUND.getValue());
		orderRefund.setCreateTime(new Date());
		orderRefund.setUserId(AuthUtil.getUserId());
		return orderRefund;
	}
}
