using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Sockeye.Biz;
using Newtonsoft.Json;

namespace Sockeye.Models
{
    //https://stackoverflow.com/questions/46517584/how-to-add-a-parent-record-with-its-children-records-in-ef-core#46615455
    public class IntegrationItem
    {
        public long Id { get; set; }
        public uint Concurrency { get; set; }

        [Required]
        public long IntegrationId { get; set; }

        [Required]
        public long ObjectId { get; set; }
        [Required]
        public SockType SockType { get; set; }
        [Required]
        public string IntegrationItemId { get; set; }//foreign id (e.g. QB Id)
        public string IntegrationItemName { get; set; }//foreign object's name for UI, not required if not displayed anywhere
        public DateTime? LastSync { get; set; }//optional, used by qbi
        public string IntegrationItemData { get; set; }//foreign object data store for this item, unused by any Sockeye add-on's in the past but might be useful for others, expect json or xml or some other text value here


        [JsonIgnore]
        public Integration Integration { get; set; }

    }//eoc

}//eons

// CREATE TABLE [dbo].[AINTEGRATIONMAP](
// [AID] [uniqueidentifier] NOT NULL,
// [ACREATED] [datetime] NOT NULL,
// [AMODIFIED] [datetime] NOT NULL,
// [ACREATOR] [uniqueidentifier] NOT NULL,
// [AMODIFIER] [uniqueidentifier] NOT NULL,
// [AINTEGRATIONID] [uniqueidentifier] NOT NULL,
// [AROOTOBJECTID] [uniqueidentifier] NOT NULL, <--Now "ObjectId"
// [AROOTOBJECTTYPE] [smallint] NOT NULL, <-- now "SockType"
// [AFOREIGNID] [nvarchar](255) NOT NULL, <-- renamed to  "IntegrationItemId" still 255 char string
// [ANAME] [nvarchar](255) NULL, <--keep rename to "IntegrationItemName"
// [AFOREIGNCHECKSUM] [nvarchar](255) NULL, drop was not used and thsi is hwat the lastsynch is for anyway
// [ASOCKEYECHECKSUM] [nvarchar](255) NULL,  drop was not used and thsi is hwat the lastsynch is for anyway
// [AMAPOBJECT] [image] NULL, Now "IntegrationItemData"
// [AMAPOBJECTSIZE] [int] NULL, dropped, expects to be json data now, size is irrelevant as it's not a binary object anymore
// [ALASTSYNC] [datetime] NOT NULL,