using Agent86.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Agent86.Pages
{
    public class InsertModel : PageModel
    {
        [BindProperty]
        public string myRole { get; set; }
        [BindProperty]
        public List<Scene> Scenes { get; set; } = new();
        [BindProperty]
        public Scene theScene { get; set; } = new();



        public void OnGet()
        {
            myRole = User.Claims.FirstOrDefault(c => c.Type == "roles")?.Value;
            if (theScene.role == "error")
            {
                // Handle the case where the scene role is not set
                Scenes = [.. new Persistence.DbOps().GetScenes().OrderBy(s => s.role)];
            }
        }

        public IActionResult OnPost(string action = "error", string projectName = "error", string quest = "error", string member = "error", string customer = "error", string instruction = "error")
        {
            myRole = User.Claims.FirstOrDefault(c => c.Type == "roles")?.Value;
            if (myRole == "teacher" || myRole == "owner")
            {
                if (action == "insert")
                {
                    new Persistence.DbOps().InsertScene(projectName, quest, member, customer, instruction);
                }
                return RedirectToPage("/Index");
            }
            return RedirectToPage("/Index");
        }
    }
}
