package com.cool.store.request;

import com.cool.store.entity.PointDetailInfoDO;
import com.cool.store.enums.AuditResultTypeEnum;
import com.cool.store.enums.AuditStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: PointAuditRequest
 * @Description:
 * @date 2024-04-03 14:13
 */
@Data
public class OperationAuditRequest {

    @NotNull
    @ApiModelProperty("铺位id")
    private Long pointId;

    @NotNull
    @Min(1)
    @Max(2)
    @ApiModelProperty("1通过,2拒绝")
    private Integer auditStatus;

    @ApiModelProperty("签到时间")
    private Date signTime;

    @ApiModelProperty("签到位置")
    private String signAddress;

    @ApiModelProperty("图片")
    private String pictureUrl;

    @ApiModelProperty("原因")
    private String reason;

    @ApiModelProperty("店长数量")
    private Integer shopManagerNum;

    @ApiModelProperty("店长基本工资")
    private Integer shopManagerFee;

    @ApiModelProperty("店员数量")
    private Integer clerkNum;

    @ApiModelProperty("店员基本工资")
    private Integer clerkFee;

    @ApiModelProperty("营运人员签字")
    private String operationUserSign;

    public boolean check() {
        if(AuditStatusEnum.PASS.getCode().equals(this.auditStatus)){
            if(Objects.isNull(this.shopManagerNum) || Objects.isNull(this.shopManagerFee) || Objects.isNull(this.clerkNum) || Objects.isNull(this.clerkFee)){
                return false;
            }
            if(StringUtils.isBlank(this.operationUserSign)){
                return false;
            }
        }else{
            if(StringUtils.isBlank(this.reason)){
                return false;
            }
        }
        return true;
    }

    public static PointDetailInfoDO convertDO(Long pointDetailId, OperationAuditRequest request){
        PointDetailInfoDO pointDetailInfo = new PointDetailInfoDO();
        pointDetailInfo.setId(pointDetailId);
        pointDetailInfo.setPointId(request.getPointId());
        pointDetailInfo.setShopManagerNum(request.getShopManagerNum());
        pointDetailInfo.setShopManagerFee(request.getShopManagerFee());
        pointDetailInfo.setClerkNum(request.getClerkNum());
        pointDetailInfo.setClerkFee(request.getClerkFee());
        pointDetailInfo.setOperationUserSign(request.getOperationUserSign());
        pointDetailInfo.setOperationUserSignTime(new Date());
        if(Objects.nonNull(request.getShopManagerNum()) && Objects.nonNull(request.getShopManagerFee()) && Objects.nonNull(request.getClerkNum()) && Objects.nonNull(request.getClerkFee())){
            pointDetailInfo.setStaffFee(String.valueOf((request.getShopManagerNum() * request.getShopManagerFee()) + (request.getClerkNum() * request.getClerkFee())));
        }
        return pointDetailInfo;
    }

}
