using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Enums;

namespace CMSMicroservice.Application.UserCQ.Commands.MigrateNetworkParentId;

public class MigrateNetworkParentIdCommandHandler : IRequestHandler<MigrateNetworkParentIdCommand, MigrateNetworkParentIdResult>
{
    private readonly IApplicationDbContext _context;
    private readonly ILogger<MigrateNetworkParentIdCommandHandler> _logger;

    public MigrateNetworkParentIdCommandHandler(
        IApplicationDbContext context,
        ILogger<MigrateNetworkParentIdCommandHandler> logger)
    {
        _context = context;
        _logger = logger;
    }

    public async Task<MigrateNetworkParentIdResult> Handle(MigrateNetworkParentIdCommand request, CancellationToken cancellationToken)
    {
        _logger.LogInformation("=== ParentId Migration No Longer Needed (ParentId Removed) ===");
        
        // ParentId has been removed from User entity
        // This migration is no longer necessary
        return new MigrateNetworkParentIdResult
        {
            Success = true,
            Message = "ParentId field has been removed. This migration is obsolete.",
            MigratedCount = 0,
            SkippedCount = 0,
            ValidationErrors = new List<string>()
        };
    }
}
