using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoviDok.Api;
using CoviDok.Api.Request;
using CoviDok.Api.Response;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;


namespace CoviDok.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AuthController : ControllerBase
    {
        // POST: /api/Auth/login
        [HttpPost("login")]
        public async Task<ActionResult<AuthIdentity>> PostLogin(AuthLogin authLogin)
        {
            AuthIdentity authIdentity = new AuthIdentity();
            if (authLogin.Email == "a" && authLogin.Password == "a")
            {
                authIdentity.FirstName = "Sajt";
                authIdentity.LastName = "Osperec";
                authIdentity.Id = "asdfasdfadf";
                authIdentity.Role = Api.Role.Doc;
                return authIdentity;
            }
            return Unauthorized();
        }

        // POST: /api/Auth/register
        [HttpPost("register")]
        public async Task<ActionResult<GenericResponse>> PostRegister(AuthRegistration authRegistration)
        {
            // System.Diagnostics.Debug.WriteLine(authRegistration.ToString());
            GenericResponse genericResponse = new GenericResponse();
            if (authRegistration.Email == "a")
            {
                genericResponse.Status = Status.Error;
                genericResponse.Body["reason"] = authRegistration.Email + " is already registered!";
            } else if (authRegistration.Password == "1")
            {
                genericResponse.Status = Status.Error;
                genericResponse.Body["reason"] = "Password does not meet complexity requirements!";
            }

            return genericResponse;
        }

        // POST /api/Auth/child
        [HttpPost("child")]
        public async Task<ActionResult<GenericResponse>> PostAddChild(AuthChild authChild)
        {
            GenericResponse genericResponse = new GenericResponse();
            if (authChild.SessionID != "id")
            {
                return Unauthorized();
            }
            else if (authChild.SocSecNum == "111111111")
            {
                genericResponse.Status = Status.Error;
                genericResponse.Body["reason"] = "SSN Already exists!";
            }
            else
            {
                genericResponse.Body["childID"] = "asdfaasdas";
            }

            return genericResponse;
        }
    }
}