/*
* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: Emails.Transactional
* File: EmailTransaction.cs
*
* EmailTransaction.cs is part of Emails.Transactional which is part of the larger
* VNLib collection of libraries and utilities.
*
* Emails.Transactional is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License,
* or (at your option) any later version.
*
* Emails.Transactional is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Emails.Transactional. If not, see http://www.gnu.org/licenses/.
*/
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using VNLib.Plugins.Essentials;
using VNLib.Plugins.Extensions.Data;
using VNLib.Plugins.Extensions.Data.Abstractions;
namespace Emails.Transactional
{
///
/// Represents an email transaction request and its status reflected
/// in the database
///
internal class EmailTransaction : DbModelBase, IUserEntity
{
///
[Key]
[MaxLength(64)]
[JsonPropertyName("id")]
public override string Id { get; set; }
///
[JsonIgnore]
public override DateTime Created { get; set; }
///
[JsonIgnore]
public override DateTime LastModified { get; set; }
///
/// The sever side user-id that send the email
///
[JsonIgnore]
[MaxLength(64)]
public string? UserId { get; set; }
//To address
[JsonIgnore]
public string? To
{
//Use json to serialize/deserialze the to addresses
get => JsonSerializer.Serialize(ToAddresses, Statics.SR_OPTIONS);
set => ToAddresses = JsonSerializer.Deserialize>(value!, Statics.SR_OPTIONS);
}
///
/// A dictionary of to email address and name pairs
///
[NotMapped]
[JsonPropertyName("to")]
public Dictionary? ToAddresses { get; set; }
//From
///
/// The from email address
///
[JsonPropertyName("from")]
public string? From { get; set; }
///
/// The optional from name (not mapped in db)
///
[NotMapped]
[JsonPropertyName("from_name")]
public string? FromName { get; set; }
///
/// The email subject
///
[JsonPropertyName("subject")]
public string? Subject { get; set; }
//CC names
//ccs are stored in the db as a json serialized string
[JsonIgnore]
public string Ccs
{
//Use json to serialize/deserialze the to addresses
get => JsonSerializer.Serialize(CcAddresses, Statics.SR_OPTIONS);
set => CcAddresses = JsonSerializer.Deserialize>(value, Statics.SR_OPTIONS);
}
[JsonPropertyName("cc")]
[NotMapped]
public Dictionary? CcAddresses { get; set; }
//BCC Names
//bccs are stored in the db as a json serialized string
[JsonIgnore]
public string Bccs
{
//Store bccs as a comma separated list of addresses
get => JsonSerializer.Serialize(BccAddresses, Statics.SR_OPTIONS);
set => BccAddresses = JsonSerializer.Deserialize>(value, Statics.SR_OPTIONS);
}
///
/// A dictionary of bcc addresses and names
///
[JsonPropertyName("bcc")]
[NotMapped]
public Dictionary? BccAddresses { get; set; }
///
/// The replyto email address
///
[JsonPropertyName("reply_to")]
public string? ReplyTo { get; set; }
///
/// Optional reply-to name for the address (not stored in db)
///
[NotMapped]
[JsonPropertyName("reply_to_name")]
public string? ReplyToName { get; set; }
///
/// The object id of the template to send
///
[JsonPropertyName("template_id")]
public string? TemplateId { get; set; }
///
/// The result of the STMP transaction
///
[JsonIgnore]
public string? Result { get; set; }
///
/// Variables requested from the client to embed in the template
/// during processing. These are not stored in the database
///
[NotMapped]
[JsonPropertyName("variables")]
public Dictionary? Variables { get; set; }
}
}