using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using rockfishCore.Models;
using rockfishCore.Util;

namespace rockfishCore.Controllers
{
    [Produces("text/plain")]
    [Route("rvr")]
    public class RvrController : Controller //RAVEN trial license request 
    {
        private readonly rockfishContext _context;

        public RvrController(rockfishContext context)
        {
            _context = context;
        }


        [HttpGet]
        public ActionResult Get([FromQuery] Guid dbid, [FromQuery] string email, [FromQuery] string regto)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (dbid == Guid.Empty)
            {
                return BadRequest("The requested DB ID was empty and not valid");
            }

            //TODO: closer to release as ROCKFISH might change before then

            //Attempt to match customer by dbid if not then create new customer of trial type for the indicated dbid and regto
            //ensure this email goes into the adminEmail array if not already there

            //Flag customer record has having an unfulfilled trial request 

            //If it's a new customer or an existing one with non-matching email then send a verification email to the customer

            //When a response is spotted in email then Rockfish should see it and flag the customer as verified
                //Probably some general purpose email Verify code would be helpful here as it would likely be useful for all manner of things

            //When user releases trial in Rockfish a license key will be generated ready for the customers RAVEN to retrieve

            return Ok("Request accepted. Awaiting email verification and approval.");


        }


    }//eoc
}//eons