package com.dji.sample.manage.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.dji.sample.manage.model.entity.UserPasswordHistoryEntity;

public interface IUserPasswordHistoryService extends IService<UserPasswordHistoryEntity> {

    /**
     * Save a new password record to history.
     * Keeps only the most recent {@code maxHistory} records per user.
     *
     * @param userId      user uuid
     * @param workspaceId workspace id
     * @param encodedPassword BCrypt-encoded password to record
     * @param maxHistory  maximum number of records to retain (e.g. 8)
     */
    void savePasswordHistory(String userId, String workspaceId, String encodedPassword, int maxHistory);

    /**
     * Check whether the plain-text password matches any of the recent {@code maxHistory} history records.
     *
     * @param userId      user uuid
     * @param rawPassword plain-text password to check
     * @param maxHistory  number of history records to check
     * @return true if the password was recently used
     */
    boolean isPasswordRecentlyUsed(String userId, String rawPassword, int maxHistory);

}
