using OrpaonVision.Core.Results;
using OrpaonVision.Model.Security;
using OrpaonVision.Model.Configuration;
namespace OrpaonVision.Core.Security;
///
/// 机种权限服务接口。
///
public interface IProductPermissionService
{
///
/// 检查用户是否具有指定机种的权限。
///
/// 用户ID。
/// 机种ID。
/// 权限类型。
/// 取消令牌。
/// 权限检查结果。
Task> CheckPermissionAsync(Guid userId, Guid productTypeId, ProductPermissionType permissionType, CancellationToken cancellationToken = default);
///
/// 检查用户是否具有指定机种编码的权限。
///
/// 用户ID。
/// 机种编码。
/// 权限类型。
/// 取消令牌。
/// 权限检查结果。
Task> CheckPermissionByCodeAsync(Guid userId, string productTypeCode, ProductPermissionType permissionType, CancellationToken cancellationToken = default);
///
/// 获取用户在指定机种的权限列表。
///
/// 用户ID。
/// 机种ID。
/// 取消令牌。
/// 权限列表。
Task>> GetUserPermissionsAsync(Guid userId, Guid productTypeId, CancellationToken cancellationToken = default);
///
/// 授予用户机种权限。
///
/// 用户ID。
/// 机种ID。
/// 权限类型。
/// 过期时间(可选)。
/// 备注。
/// 取消令牌。
/// 授权结果。
Task> GrantPermissionAsync(Guid userId, Guid productTypeId, ProductPermissionType permissionType, DateTime? expiresAtUtc = null, string? remark = null, CancellationToken cancellationToken = default);
///
/// 撤销用户机种权限。
///
/// 权限ID。
/// 撤销原因。
/// 取消令牌。
/// 撤销结果。
Task RevokePermissionAsync(Guid permissionId, string reason, CancellationToken cancellationToken = default);
///
/// 检查机种是否被锁定。
///
/// 机种ID。
/// 锁定类型。
/// 取消令牌。
/// 锁定检查结果。
Task> IsProductLockedAsync(Guid productTypeId, ProductLockType lockType, CancellationToken cancellationToken = default);
///
/// 锁定机种。
///
/// 机种ID。
/// 锁定类型。
/// 锁定原因。
/// 预计解锁时间(可选)。
/// 取消令牌。
/// 锁定结果。
Task> LockProductAsync(Guid productTypeId, ProductLockType lockType, string lockReason, DateTime? expectedUnlockAtUtc = null, CancellationToken cancellationToken = default);
///
/// 解锁机种。
///
/// 锁定记录ID。
/// 解锁原因。
/// 取消令牌。
/// 解锁结果。
Task UnlockProductAsync(Guid lockRecordId, string unlockReason, CancellationToken cancellationToken = default);
///
/// 验证机种切换权限。
///
/// 用户ID。
/// 源机种ID。
/// 目标机种ID。
/// 是否强制切换。
/// 取消令牌。
/// 验证结果。
Task> ValidateSwitchPermissionAsync(Guid userId, Guid? sourceProductTypeId, Guid targetProductTypeId, bool isForced = false, CancellationToken cancellationToken = default);
///
/// 记录机种切换。
///
/// 用户ID。
/// 用户姓名。
/// 用户角色。
/// 源机种ID。
/// 目标机种ID。
/// 切换类型。
/// 切换原因。
/// 是否强制切换。
/// 强制切换原因。
/// 取消令牌。
/// 记录结果。
Task> RecordSwitchAsync(Guid userId, string userName, string userRole, Guid? sourceProductTypeId, Guid targetProductTypeId, ProductSwitchType switchType, string switchReason, bool isForced = false, string? forcedReason = null, CancellationToken cancellationToken = default);
///
/// 获取机种切换历史记录。
///
/// 机种ID(可选)。
/// 用户ID(可选)。
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 切换记录列表。
Task>> GetSwitchHistoryAsync(Guid? productTypeId = null, Guid? userId = null, DateTime? startTime = null, DateTime? endTime = null, CancellationToken cancellationToken = default);
///
/// 获取机种锁定记录。
///
/// 机种ID。
/// 是否包含已解锁的记录。
/// 取消令牌。
/// 锁定记录列表。
Task>> GetLockRecordsAsync(Guid productTypeId, bool includeUnlocked = false, CancellationToken cancellationToken = default);
}
///
/// 机种切换验证结果。
///
public sealed class ProductSwitchValidationResult
{
///
/// 是否允许切换。
///
public bool CanSwitch { get; init; }
///
/// 验证消息。
///
public string Message { get; init; } = string.Empty;
///
/// 警告信息。
///
public List Warnings { get; init; } = new();
///
/// 错误信息。
///
public List Errors { get; init; } = new();
///
/// 需要审批。
///
public bool RequiresApproval { get; init; }
///
/// 审批人列表。
///
public List Approvers { get; init; } = new();
///
/// 源机种信息。
///
public ProductTypeModel? SourceProduct { get; init; }
///
/// 目标机种信息。
///
public ProductTypeModel? TargetProduct { get; init; }
///
/// 当前用户权限。
///
public List CurrentPermissions { get; init; } = new();
///
/// 所需权限。
///
public List RequiredPermissions { get; init; } = new();
///
/// 验证时间(UTC)。
///
public DateTime ValidatedAtUtc { get; init; } = DateTime.UtcNow;
}