using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.ViewModels;

namespace New_College.Api.Controllers.Front
{
    [Route("api/front/[controller]/[action]")]
    [ApiController]
    public class RegionController : ControllerBase
    {
        private readonly ISysRegionServices sysRegionServices;
        public RegionController(ISysRegionServices ISysRegionServices)
        {
            sysRegionServices = ISysRegionServices;
        }

        /// <summary>
        /// 获取省市区
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<List<SysRegionResult>>> GetRegionList([FromQuery] SysRegionQuery query)
        {
            List<SysRegionResult> list = new List<SysRegionResult>() { };
            list.Add(new SysRegionResult() { Id = 0, Code = "0", Name = "全国" });
            var result = await sysRegionServices.GetRegionList(query);
            list.AddRange(result);
            return new MessageModel<List<SysRegionResult>>()
            {
                success = true,
                msg = "成功",
                response = list
            };
        }
    }
}
