using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace Blahblah.FlowerStory.Server.Data.Model;

/// <summary>
/// 花草对象
/// </summary>
[Table("flowers")]
public class FlowerItem : ILocation
{
    /// <summary>
    /// 自增 id，主键
    /// </summary>
    [Column("fid")]
    [Key]
    [Required]
    public int Id { get; set; }

    /// <summary>
    /// 所有人 id
    /// </summary>
    [Column("uid")]
    [ForeignKey(nameof(Owner))]
    [Required]
    public required int OwnerId { get; set; }

    /// <summary>
    /// 所有人
    /// </summary>
    [JsonIgnore]
    public UserItem? Owner { get; set; }

    /// <summary>
    /// 类别 id
    /// </summary>
    [Column("categoryid")]
    [Required]
    public required int CategoryId { get; set; }

    /// <summary>
    /// 花草名称
    /// </summary>
    [Column("name")]
    [Required]
    public required string Name { get; set; }

    /// <summary>
    /// 购买时间
    /// </summary>
    [Column("datebuy")]
    [Required]
    [JsonPropertyName("dateBuy")]
    public required long DateBuyUnixTime { get; set; }

    /// <summary>
    /// 购买花费
    /// </summary>
    [Column("cost", TypeName = "real")]
    public decimal? Cost { get; set; }

    /// <summary>
    /// 购买渠道
    /// </summary>
    [Column("purchase")]
    public string? Purchase { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    [Column("memo")]
    public string? Memo { get; set; }

    /// <summary>
    /// 购买时间
    /// </summary>
    [NotMapped]
    [JsonIgnore]
    public DateTimeOffset DateBuy => DateTimeOffset.FromUnixTimeMilliseconds(DateBuyUnixTime);

    /// <summary>
    /// 封面相关照片
    /// </summary>
    public ICollection<PhotoItem>? Photos { get; set; }

    /// <summary>
    /// 纬度
    /// </summary>
    [Column("latitude")]
    public double? Latitude { get; set; }

    /// <summary>
    /// 经度
    /// </summary>
    [Column("longitude")]
    public double? Longitude { get; set; }

    /// <summary>
    /// 距离（米）
    /// </summary>
    [NotMapped]
    public int? Distance { get; set; }
}
