using Lada.Framework.Data.Domains.Identity;

namespace Ladaer.BackEnd.Infrastructures.Services.Identity
{
    /// <summary>
    /// Service for migrating from old role naming convention to new Controller.Action pattern
    /// </summary>
    public interface IRoleMigrationService
    {
        /// <summary>
        /// Tạo tất cả Role mới theo pattern Controller.Action
        /// </summary>
        /// <returns>Danh sách Role đã tạo</returns>
        Task<List<string>> CreateNewRolesAsync();

        /// <summary>
        /// Tạo Permission Groups mặc định tương ứng với các vai trò cũ
        /// </summary>
        /// <returns>Danh sách Permission đã tạo</returns>
        Task<List<string>> CreateDefaultPermissionGroupsAsync();

        /// <summary>
        /// Migration Users từ old roles sang Permission Groups
        /// </summary>
        /// <returns>Số lượng User đã migration</returns>
        Task<int> MigrateUsersToPermissionGroupsAsync();

        /// <summary>
        /// Lấy danh sách Role mới cần tạo
        /// </summary>
        /// <returns>Dictionary với key là role name, value là description</returns>
        Dictionary<string, string> GetNewRolesToCreate();

        /// <summary>
        /// Lấy mapping từ old roles sang Permission Groups
        /// </summary>
        /// <returns>Dictionary với key là old role, value là Permission Group name</returns>
        Dictionary<string, string> GetOldRoleToPermissionMapping();

        /// <summary>
        /// Kiểm tra xem migration đã hoàn thành chưa
        /// </summary>
        /// <returns>True nếu đã migration xong</returns>
        Task<bool> IsMigrationCompletedAsync();

        /// <summary>
        /// Chạy full migration process
        /// </summary>
        /// <returns>Migration result</returns>
        Task<MigrationResult> RunFullMigrationAsync();
    }

    /// <summary>
    /// Result of migration process
    /// </summary>
    public class MigrationResult
    {
        public bool Success { get; set; }
        public List<string> CreatedRoles { get; set; } = new List<string>();
        public List<string> CreatedPermissions { get; set; } = new List<string>();
        public int MigratedUsers { get; set; }
        public List<string> Errors { get; set; } = new List<string>();
        public string Message { get; set; } = string.Empty;
    }
}
