using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JtkMainServer.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace JtkMainServer.Pages.Manage {
    public class SaleModel : PageModel {
        public string Message { get; set; }

        public IActionResult OnGet() {
            var userId = HttpContext.Session.GetString("LoggedInUserId");
            if (string.IsNullOrWhiteSpace(userId)) {
                // 로그인 안 했을 시, 로그인 페이지로
                HttpContext.Session.SetString("RequestedPage", "Manage/Sales");
                return RedirectToPage("/Login");
            }
            if (userId != "admin") {
                return RedirectToPage("/Index");
            }

            if (HttpContext.Request.Query.TryGetValue("type", out var types) == false || types.Count < 1) {
                return RedirectToPage("./Sales");
            }
            var type = types[0];
            ViewData["Type"] = type;
            if (new string[] { "charge", "payment" }.Contains(type) == false) {
                return RedirectToPage("./Sales");
            }

            return Page();
        }
        public IActionResult OnPost() {
            return OnGet();
        }
    }
}
