using AssetManager.API.DTOs;
using AssetManager.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace AssetManager.API.Controllers;

[ApiController]
[Route("api/app")]
[Authorize]
public class AppController : ControllerBase
{
    private readonly ILogger<AppController> _logger;

    public AppController(ILogger<AppController> logger)
    {
        _logger = logger;
    }

    [HttpGet("info")]
    public ActionResult<ApiResponse<AppInfoResponse>> GetAppInfo()
    {
        try
        {
            _logger.LogInformation("Request to get app info");
            
            // 模拟返回应用信息
            var response = new AppInfoResponse
            {
                Version = "1.0.0",
                CurrentDate = DateTime.Now.ToString("yyyy-MM-dd"),
                LatestVersion = "1.0.1",
                UpdateAvailable = true
            };

            _logger.LogInformation("App info retrieved successfully");
            
            return Ok(new ApiResponse<AppInfoResponse>
            {
                Code = AssetManager.Models.StatusCodes.Success,
                Data = response,
                Message = "Success"
            });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error retrieving app info");
            
            return StatusCode(AssetManager.Models.StatusCodes.InternalServerError, new ApiResponse<AppInfoResponse>
            {
                Code = AssetManager.Models.StatusCodes.InternalServerError,
                Data = null,
                Message = ex.Message
            });
        }
    }
}