using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Nirvana.Common;
using Waste.Application;
using Waste.Domain;

namespace Waste.Web.Entry.Pages.Device
{
    public class EditModel : PageModel
    {
        private readonly IDeviceService _deviceService;
        public DeviceSubmit data = new DeviceSubmit();
        public List<SelectListItem> devicetypes = new List<SelectListItem>();
        public List<SelectListItem> devicenettypes = new List<SelectListItem>();
        public string provinceval = "";
        public string cityval = "";
        public string areaval = "";
        public EditModel(IDeviceService deviceService)
        {
            _deviceService = deviceService;
        }
        public async Task OnGetAsync(Guid? id =null)
        {
            devicetypes = EnumHelper.GetEnumDictionary<DeviceType>().Select(x => new SelectListItem
            {
                Value = x.Key.ToString(),
                Text = x.Value
            }).ToList();
            devicenettypes = EnumHelper.GetEnumDictionary<DeviceNetType>().Select(x => new SelectListItem
            {
                Value = x.Key.ToString(),
                Text = x.Value
            }).ToList();
            if (id.HasValue && id.Value != Guid.Empty)
            {
                data = await _deviceService.DetailAsync(id.Value);
                provinceval = data.Province;
                cityval = data.City;
                areaval = data.Area;
            }
        }
    }
}
