using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Shride.Models
{
    public class UserInitializer
    {
        public static async Task EnsurePopulated(IServiceProvider service)
        {
            var userManager = service.GetRequiredService<UserManager<IdentityUser>>();

            await CreateUsers(userManager);
        }

        private static async Task CreateUsers(UserManager<IdentityUser> uMgr)
        {
            if (await uMgr.FindByEmailAsync("test-passenger@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("Passenger");
                await uMgr.CreateAsync(user, "ettStarktLösenord1");
            }

            if (await uMgr.FindByEmailAsync("test-arranger@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("Arranger");
                await uMgr.CreateAsync(user, "ettStarktLösenord2");
                
            }

            if (await uMgr.FindByEmailAsync("rod@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("rod");
                await uMgr.CreateAsync(user, "ettStarktLösenord1");

            }

            if (await uMgr.FindByEmailAsync("orange@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("orange");
                await uMgr.CreateAsync(user, "ettStarktLösenord1");

            }

            if (await uMgr.FindByEmailAsync("yellow@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("yellow");
                await uMgr.CreateAsync(user, "ettStarktLösenord1");

            }

            if (await uMgr.FindByEmailAsync("green@mail.com") == null)
            {
                IdentityUser user = new IdentityUser("green");
                await uMgr.CreateAsync(user, "ettStarktLösenord1");

            }

        }

    }
}
