using System.Text.Json.Serialization;
namespace CORP_MAUI.Models;
///
/// Модель документа
///
public class Document
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;
[JsonPropertyName("description")]
public string Description { get; set; } = string.Empty;
[JsonPropertyName("uploaded_by")]
public User? UploadedBy { get; set; }
[JsonPropertyName("uploaded_at")]
public DateTime UploadedAt { get; set; }
[JsonPropertyName("sent_to_all")]
public bool SentToAll { get; set; }
[JsonPropertyName("departments")]
public List? Departments { get; set; }
[JsonPropertyName("recipients")]
public List? Recipients { get; set; }
[JsonPropertyName("file_url")]
public string FileUrl { get; set; } = string.Empty;
[JsonPropertyName("is_acknowledged")]
public bool IsAcknowledged { get; set; }
// Вычисляемые свойства для отображения
///
/// Имя загрузившего документ
///
[JsonIgnore]
public string UploaderName => UploadedBy?.FullName ?? "Неизвестный";
///
/// URL аватара загрузившего
///
[JsonIgnore]
public string UploaderAvatarUrl => UploadedBy?.Avatar ?? UploadedBy?.AvatarUrl ?? string.Empty;
///
/// Форматированная дата загрузки
///
[JsonIgnore]
public string DisplayUploadedAt => UploadedAt.ToString("dd.MM.yyyy HH:mm");
///
/// Расширение файла (для иконки)
///
[JsonIgnore]
public string FileExtension
{
get
{
if (string.IsNullOrEmpty(FileUrl)) return string.Empty;
try
{
// Декодируем URL и получаем расширение
string decodedUrl = Uri.UnescapeDataString(FileUrl);
int lastDot = decodedUrl.LastIndexOf('.');
if (lastDot > 0 && lastDot < decodedUrl.Length - 1)
{
return decodedUrl.Substring(lastDot + 1).ToLower();
}
}
catch
{
// Игнорируем ошибки декодирования
}
return string.Empty;
}
}
///
/// Иконка типа документа (эмодзи)
///
[JsonIgnore]
public string FileIcon
{
get
{
return FileExtension switch
{
"pdf" => "📕",
"doc" or "docx" => "📘",
"xls" or "xlsx" => "📗",
"ppt" or "pptx" => "📙",
"txt" => "📄",
"jpg" or "jpeg" or "png" or "gif" or "webp" => "🖼️",
"zip" or "rar" or "7z" => "📦",
_ => "📄"
};
}
}
///
/// Цвет статуса ознакомления
///
[JsonIgnore]
public Color AcknowledgedColor => IsAcknowledged
? Color.FromArgb("#28A745") // Зеленый
: Color.FromArgb("#FFC107"); // Желтый
///
/// Текст статуса ознакомления
///
[JsonIgnore]
public string AcknowledgedText => IsAcknowledged ? "Ознакомлен" : "Не ознакомлен";
///
/// Иконка статуса ознакомления
///
[JsonIgnore]
public string AcknowledgedIcon => IsAcknowledged ? "✅" : "⏳";
///
/// Короткое описание файла
///
[JsonIgnore]
public string ShortDescription
{
get
{
if (!string.IsNullOrEmpty(Description))
{
return Description.Length > 100 ? Description.Substring(0, 100) + "..." : Description;
}
return SentToAll ? "Для всех сотрудников" : "Персональный документ";
}
}
}