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

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yuchen.saas.park.api.commons.domain.DoorAccessControlConfigSetting;
import com.yuchen.saas.park.api.commons.domain.DoorAccessControlConfigSettingOne;
import com.yuchen.saas.park.api.commons.entity.SimpleEntity;
import com.yuchen.saas.park.api.commons.enums.DoorAccessControlConfigMappingType;
import com.yuchen.saas.park.api.config.convert.DoorAccessControlMappingTypeConverter;
import lombok.Data;

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

/**
 * 当前只有时间配置(计划模板)
 * 其它配置(全量)跟随用户
 *
 * @see DoorAccessControlConfigSetting
 */
@TableName(autoResultMap = true)
@Data
public class DoorAccessControlConfigMapping extends SimpleEntity {
    @TableField(typeHandler = DoorAccessControlMappingTypeConverter.class)
    private DoorAccessControlConfigMappingType type;

    /**
     * 用户(组)|部门引用(id)
     */
    @Positive
    private long userRefId;
    /**
     * 当为部门时是否递归(包含下级)
     */
    @TableField("is_recursive")
    private boolean recursive;

    /**
     * 门禁(组)引用(id)
     */
    @Positive
    private long doorAccessControlRefId;

    @Positive
    private long timeConfigId;
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    @Nullable
    private LocalDateTime effectiveStartTime;
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    @Nullable
    private LocalDateTime effectiveEndTime;

    public DoorAccessControlConfigMapping setSetting(DoorAccessControlConfigSetting o) {
        return this.setTimeConfigId(o.getTimeConfigId()).setEffectiveStartTime(o.getEffectiveStartTime()).setEffectiveEndTime(o.getEffectiveEndTime());
    }

    public DoorAccessControlConfigMapping setSettingOne(DoorAccessControlConfigSettingOne o) {
        return this.setTimeConfigId(o.getTimeConfigId()).setEffectiveStartTime(o.getEffectiveStartTime()).setEffectiveEndTime(o.getEffectiveEndTime());
    }
}
