package com.yuchen.saas.park.api.entity.door.config;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yuchen.saas.park.api.commons.entity.SimpleEntity;
import lombok.Data;
import lombok.val;

import javax.annotation.Nullable;
import javax.validation.constraints.Positive;
import java.time.LocalDateTime;

@TableName(autoResultMap = true)
@Data
public class DoorAccessControlConfigIssueTaskDetails extends SimpleEntity {
    @Positive
    private long doorAccessControlConfigIssueTaskId;

    @TableField("is_successful")
    private boolean successful;

    @TableField("is_canceled")
    private boolean canceled;

    /**
     * 处理时间起讫时间
     */
    @Nullable
    private LocalDateTime processingStartTime;
    @Nullable
    private LocalDateTime processingEndTime;

    @Nullable
    private String processingFailureReason;

    public DoorAccessControlConfigIssueTaskDetails start() {
        return this.setProcessingStartTime(LocalDateTime.now());
    }

    public DoorAccessControlConfigIssueTaskDetails cancel() {
        val now = LocalDateTime.now();
        return this.setProcessingStartTime(now).setProcessingEndTime(now).setCanceled(true);
    }
}
