using Hotline.Application.Snapshot.Contracts;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Tools;
using Hotline.Snapshot.IRepository;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;

namespace Hotline.Api.Controllers.Snapshot;

[Description("随手拍用户管理")]
public class SnapshotUserController : BaseController
{
    private readonly ISnapshotUserApplication _snapshotUserApplication;
    private readonly ISafetyTypeRepository _safetyTypeRepository;

    public SnapshotUserController(ISnapshotUserApplication snapshotUserApplication, ISafetyTypeRepository safetyTypeRepository)
    {
        _snapshotUserApplication = snapshotUserApplication;
        _safetyTypeRepository = safetyTypeRepository;
    }

    /// <summary>
    /// 获取添加安全志愿者和安全员分类关系的基础数据
    /// </summary>
    /// <returns></returns>
    [HttpGet("citizen_relation/basedata")]
    public async Task<Dictionary<string, object>> GetCitizenRelationSafetyTypeBase()
    {
        var safetyTypes = await _safetyTypeRepository.Queryable()
            .Select(m => new { m.Id, m.Name})
            .ToListAsync(HttpContext.RequestAborted);
        return new Dictionary<string, object>
        {
            { "safetyTypes", safetyTypes }
        };
    }

    /// <summary>
    /// 安全志愿者列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("citizen_relation")]
    public async Task<PagedDto<CitizenRelationSafetyTypeOutDto>> GetCitizenRelationSafetyType([FromQuery] CitizenRelationSafetyTypeInDto dto)
        => (await _snapshotUserApplication.GetCitizenRelationSafetyType(dto).ToPagedListAsync(dto)).ToPaged();

    /// <summary>
    /// 添加安全志愿者和安全员分类关系
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("citizen_relation")]
    public async Task AddCitizenRelationSafetyTypeInDto([FromBody]AddCitizenRelationSafetyTypeInDto dto)
        => await _snapshotUserApplication.AddCitizenRelationSafetyType(dto, HttpContext.RequestAborted);

    /// <summary>
    /// 批量删除安全志愿者分类关系
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpDelete("citizen_relation")]
    public async Task DeleteCitizenRelationSafetyType([FromBody] DeleteCitizenRelationSafetyTypeInDto dto)
        => await _snapshotUserApplication.DeleteCitizenRelationSafetyAsync(dto);

    /// <summary>
    /// 搜索安全志愿者
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("citizen")]
    public async Task<PagedDto<GetThirdCitizenOutDto>> GetThirdCitizenAsync([FromQuery] GetThirdCitizenInDto dto)
        => (await _snapshotUserApplication.GetThirdCitizenAsync(dto).ToPagedListAsync(dto)).ToPaged();
}
