Files
EbayListingTool/EbayListingTool/Models/ListingDraft.cs

190 lines
4.8 KiB
C#
Raw Normal View History

using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace EbayListingTool.Models;
public enum ItemCondition
{
New,
OpenBox,
Refurbished,
Used,
ForPartsOrNotWorking
}
public enum ListingFormat
{
FixedPrice,
Auction
}
public enum PostageOption
{
RoyalMailFirstClass,
RoyalMailSecondClass,
RoyalMailTracked24,
RoyalMailTracked48,
CollectionOnly,
FreePostage
}
public class ListingDraft : INotifyPropertyChanged
{
private string _title = "";
private string _description = "";
private decimal _price;
private int _quantity = 1;
private ItemCondition _condition = ItemCondition.Used;
private ListingFormat _format = ListingFormat.FixedPrice;
private PostageOption _postage = PostageOption.RoyalMailSecondClass;
private Dictionary<string, string> _aspects = new();
private decimal _shippingCost;
private string _categoryId = "";
private string _categoryName = "";
private string _postcode = "";
private List<string> _photoPaths = new();
private string? _ebayItemId;
private string? _ebayListingUrl;
private string _sku = Guid.NewGuid().ToString("N")[..12].ToUpper();
private bool _isPosting;
private string _statusMessage = "";
public string Title
{
get => _title;
set { _title = value; OnPropertyChanged(); OnPropertyChanged(nameof(TitleCharCount)); }
}
public string TitleCharCount => $"{_title.Length}/80";
public bool TitleTooLong => _title.Length > 80;
public string Description
{
get => _description;
set { _description = value; OnPropertyChanged(); }
}
public decimal Price
{
get => _price;
set { _price = value; OnPropertyChanged(); }
}
public int Quantity
{
get => _quantity;
set { _quantity = value; OnPropertyChanged(); }
}
public ItemCondition Condition
{
get => _condition;
set { _condition = value; OnPropertyChanged(); }
}
public ListingFormat Format
{
get => _format;
set { _format = value; OnPropertyChanged(); }
}
public PostageOption Postage
{
get => _postage;
set { _postage = value; OnPropertyChanged(); }
}
public Dictionary<string, string> Aspects
{
get => _aspects;
set { _aspects = value; OnPropertyChanged(); }
}
public decimal ShippingCost
{
get => _shippingCost;
set { _shippingCost = value; OnPropertyChanged(); }
}
public string CategoryId
{
get => _categoryId;
set { _categoryId = value; OnPropertyChanged(); }
}
public string CategoryName
{
get => _categoryName;
set { _categoryName = value; OnPropertyChanged(); }
}
public string Postcode
{
get => _postcode;
set { _postcode = value; OnPropertyChanged(); }
}
public List<string> PhotoPaths
{
get => _photoPaths;
set { _photoPaths = value; OnPropertyChanged(); }
}
public string? EbayItemId
{
get => _ebayItemId;
set { _ebayItemId = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsPosted)); }
}
public string? EbayListingUrl
{
get => _ebayListingUrl;
set { _ebayListingUrl = value; OnPropertyChanged(); }
}
public string Sku
{
get => _sku;
set { _sku = value; OnPropertyChanged(); }
}
public bool IsPosting
{
get => _isPosting;
set { _isPosting = value; OnPropertyChanged(); }
}
public string StatusMessage
{
get => _statusMessage;
set { _statusMessage = value; OnPropertyChanged(); }
}
public bool IsPosted => !string.IsNullOrEmpty(_ebayItemId);
public string ConditionId => Condition switch
{
ItemCondition.New => "NEW",
ItemCondition.OpenBox => "NEW_OTHER",
ItemCondition.Refurbished => "SELLER_REFURBISHED",
ItemCondition.Used => "USED_VERY_GOOD",
ItemCondition.ForPartsOrNotWorking => "FOR_PARTS_OR_NOT_WORKING",
_ => "USED_VERY_GOOD"
};
// Numeric condition IDs for Trading API (AddItem)
public string ConditionNumericId => Condition switch
{
ItemCondition.New => "1000",
ItemCondition.OpenBox => "1500",
ItemCondition.Refurbished => "2500",
ItemCondition.Used => "3000",
ItemCondition.ForPartsOrNotWorking => "7000",
_ => "3000"
};
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? name = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}